aboutsummaryrefslogtreecommitdiffstats
path: root/config_file/parsers/ini_parser.py
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-01-19 14:57:37 -0600
committerEugene Triguba <eugenetriguba@gmail.com>2020-01-19 14:57:37 -0600
commit7f32dc49460875aedec9e555d0e5d27f23a3f2df (patch)
treef70688edfcf512e3e29fdd7f706391a0f99fb018 /config_file/parsers/ini_parser.py
parentAdd start of json_parser implementaiton (diff)
parentAdd spacing (diff)
downloadconfig-file-7f32dc49460875aedec9e555d0e5d27f23a3f2df.zip
Merge branch 'master' of github.com:eugenetriguba/config_file into json
Diffstat (limited to 'config_file/parsers/ini_parser.py')
-rw-r--r--config_file/parsers/ini_parser.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/config_file/parsers/ini_parser.py b/config_file/parsers/ini_parser.py
index 3c8f12f..549ed37 100644
--- a/config_file/parsers/ini_parser.py
+++ b/config_file/parsers/ini_parser.py
@@ -33,14 +33,27 @@ class IniParser(BaseParser):
:raises ParsingError: if the specified `section.key` is not found, in an
invalid format, or if we are unable to coerce the return value to value_type.
"""
- section, key = split_on_dot(section_key, only_last_dot=True)
+ if "." not in section_key:
+ return self.__retrieve_section(section_key, parse_type)
try:
+ section, key = split_on_dot(section_key, only_last_dot=True)
value = self.parsed_content.get(section, key)
return parse_value(value) if parse_type else value
except configparser.Error as error:
raise ParsingError(error.message)
+ def __retrieve_section(self, section, parse_type):
+ items = dict(self.parsed_content.items(section))
+
+ if not parse_type:
+ return items
+
+ for item in items:
+ items[item] = parse_value(items[item])
+
+ return items
+
def set(self, section_key, value):
"""
Sets the value of 'section.key' of the config file. If the specified section