diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-08-16 21:35:56 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-08-16 21:35:56 -0500 |
| commit | 2d091dcc5b1250b2c9457f0ff34c0c997a6a0867 (patch) | |
| tree | 7d0bbde5193b4a298f3510cfda9cd48d6bca597a /config_file/json_parser.py | |
| parent | Remove sphinx dev dependencies (diff) | |
| download | config-file-2d091dcc5b1250b2c9457f0ff34c0c997a6a0867.zip | |
Refactor parsers to enforce loads/dumps/decode_error requirement
Diffstat (limited to 'config_file/json_parser.py')
| -rw-r--r-- | config_file/json_parser.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/config_file/json_parser.py b/config_file/json_parser.py index 5314cd7..58924b4 100644 --- a/config_file/json_parser.py +++ b/config_file/json_parser.py @@ -1,15 +1,19 @@ import json +from typing import Type from .base_parser import BaseParser class JsonParser(BaseParser): def __init__(self, file_contents: str): - super().__init__( - file_contents=file_contents, - module=json, - decode_error=json.decoder.JSONDecodeError, - ) - - def stringify(self) -> str: - return json.dumps(self.parsed_content, indent=4) + super().__init__(file_contents) + + @property + def decode_error(self) -> Type[Exception]: + return json.decoder.JSONDecodeError + + def loads(self, contents: str) -> dict: + return json.loads(contents) + + def dumps(self, loaded_contents: dict) -> str: + return json.dumps(loaded_contents, indent=4) |