From 0174602093dcb097e23f6493bfd4f5d1a9fe2e3c Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Fri, 17 Jan 2020 20:31:42 -0600 Subject: Remove _split_on_dot from base parser and add it to utils Also, change the default behavior to split on every dot and split on only the last dot if specified --- config_file/parsers/base_parser.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'config_file/parsers/base_parser.py') diff --git a/config_file/parsers/base_parser.py b/config_file/parsers/base_parser.py index 38e8859..22e286a 100644 --- a/config_file/parsers/base_parser.py +++ b/config_file/parsers/base_parser.py @@ -22,7 +22,7 @@ class BaseParser(ABC): the parser and save the file when they are done using stringify(). """ self.contents = file_contents - self.parse(self.contents) + self.parsed_content = self.parse(self.contents) @abstractmethod def get(self, key, parse_type=True): @@ -74,25 +74,6 @@ class BaseParser(ABC): """ raise NotImplementedError - @staticmethod - def _split_on_dot(line: str, all_dots=False): - """ - Split a string on the first dot (.). - - :param line: The line ot split on. - :param all_dots: If the line should be split on all the dots. Defaults to - False and only splits on the first occurrence of one. - - :raises ValueError: if the line does not have a dot. - """ - if "." not in line: - raise ValueError( - "section_key must contain the section and key separated by a dot. " - + "e.g. 'section.key'" - ) - - return line.split(".") if all_dots else line.rsplit(".", 1) - class ParsingError(Exception): """Unable to parse the configuration file""" -- cgit v1.2.3