diff options
Diffstat (limited to 'config_file/ini_parser.py')
| -rw-r--r-- | config_file/ini_parser.py | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/config_file/ini_parser.py b/config_file/ini_parser.py deleted file mode 100644 index 0048288..0000000 --- a/config_file/ini_parser.py +++ /dev/null @@ -1,44 +0,0 @@ -import configparser -from io import StringIO -from typing import Type, Any - -from .base_parser import BaseParser - - -class IniParser(BaseParser): - def __init__(self, file_contents: str): - super().__init__(file_contents) - - @property - def decode_error(self) -> Type[Exception]: - return configparser.Error - - def loads(self, contents: str) -> dict: - parser = configparser.ConfigParser() - parser.read_string(contents) - - return self.__create_configparser_dict(parser) - - def dumps(self, loaded_contents: dict) -> str: - parser = configparser.ConfigParser() - buffer = StringIO() - - parser.read_dict(loaded_contents) - parser.write(buffer) - - return buffer.getvalue() - - def __create_configparser_dict(self, parser: configparser.ConfigParser) -> dict: - result = {} - items = dict(parser.items()) - - for section in parser.sections(): - result.update({str(section): dict(items[section])}) - - return result - - def get(self, search_key: str) -> Any: - retrieved_value = super().get(search_key) - return ( - retrieved_value if type(retrieved_value) is dict else str(retrieved_value) - ) |