From 954404e8a111d6445bf9313f0f27c205d88b550f Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 16 Aug 2020 22:02:04 -0500 Subject: Enforce `parsed_content` property in AbstractParser It is used in the ConfigFile object to be able to index into it. --- config_file/abstract_parser.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'config_file/abstract_parser.py') diff --git a/config_file/abstract_parser.py b/config_file/abstract_parser.py index dcc2b0f..460b238 100644 --- a/config_file/abstract_parser.py +++ b/config_file/abstract_parser.py @@ -25,6 +25,21 @@ class AbstractParser(ABC): def __init__(self, file_contents: str) -> None: self.file_contents = file_contents + @property + @abstractmethod + def parsed_content(self) -> dict: + """To be able to index into the ConfigFile object, + we have to expose the parsed dictionary object. + + Raises: + KeyError: If the key we are trying to index into + does not exist. + + Returns: + The internal contents parsed as a dictionary. + """ + raise NotImplementedError + @abstractmethod def reset_internal_contents(self, file_contents: str) -> None: """Reset the state of this parser to a new file. -- cgit v1.2.3