aboutsummaryrefslogtreecommitdiffstats
path: root/config_file
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-02-02 07:02:27 -0600
committerEugene Triguba <eugenetriguba@gmail.com>2020-02-02 07:02:27 -0600
commit99ef9872805366675f495a66594f3cd2aea68ac7 (patch)
tree1a1b10b0379a2bb5d1c7264655f9cd7db62736db /config_file
parentMerge branch 'json' of github.com:eugenetriguba/config_file into json (diff)
downloadconfig-file-99ef9872805366675f495a66594f3cd2aea68ac7.zip
Finish get method for json parser
Diffstat (limited to 'config_file')
-rw-r--r--config_file/parsers/json_parser.py10
-rw-r--r--config_file/parsers/parse_value.py8
2 files changed, 17 insertions, 1 deletions
diff --git a/config_file/parsers/json_parser.py b/config_file/parsers/json_parser.py
index c017b37..c7c20fb 100644
--- a/config_file/parsers/json_parser.py
+++ b/config_file/parsers/json_parser.py
@@ -3,6 +3,8 @@ import json
from nested_lookup import get_occurrence_of_key
from config_file.parsers.base_parser import BaseParser, ParsingError
+from config_file.parsers.parse_value import parse_value
+from config_file.utils import split_on_dot
class JsonParser(BaseParser):
@@ -17,7 +19,13 @@ class JsonParser(BaseParser):
raise ParsingError(error)
def get(self, section_key, parse_type=True):
- pass
+ split_keys = split_on_dot(section_key)
+
+ result = self.parsed_content
+ for key in split_keys:
+ result = result[key]
+
+ return parse_value(result) if parse_type else result
def set(self, section_key, value):
pass
diff --git a/config_file/parsers/parse_value.py b/config_file/parsers/parse_value.py
index 542e222..8ad4ead 100644
--- a/config_file/parsers/parse_value.py
+++ b/config_file/parsers/parse_value.py
@@ -32,6 +32,14 @@ def parse_value(value):
if can_be_parsed_as_bool(value):
return value if type(value) is bool else bool(strtobool(value))
+ if type(value) is dict:
+ parsed = {}
+
+ for item in value:
+ parsed[item] = parse_value(value[item])
+
+ return parsed
+
return value