aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-08-05 20:59:42 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-08-05 20:59:42 -0500
commitd9a2ade40e72176449433782957bf503d69cc1d8 (patch)
tree32b6408fbc58ce52270135ae7da4deaee8e15cd5
parentUpdate changelog to remove old info (diff)
downloadconfig-file-d9a2ade40e72176449433782957bf503d69cc1d8.zip
Remove custom parser and add ability to index ConfigFile
-rw-r--r--config_file/config_file.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/config_file/config_file.py b/config_file/config_file.py
index d047560..0e67794 100644
--- a/config_file/config_file.py
+++ b/config_file/config_file.py
@@ -1,9 +1,7 @@
-import inspect
from pathlib import Path
from shutil import copyfile
-from typing import Any, Optional, Type, Union
+from typing import Any, Union
-from config_file.abstract_parser import AbstractParser
from config_file.config_file_path import ConfigFilePath
from config_file.exceptions import ParsingError
from config_file.parse_value import parse_value
@@ -11,9 +9,7 @@ from config_file.utils import Default
class ConfigFile:
- def __init__(
- self, file_path: Union[str, Path], parser: Optional[Type[AbstractParser]] = None
- ) -> None:
+ def __init__(self, file_path: Union[str, Path]) -> None:
"""
Stores the config file path and expands it if needed, reads in
the file contents, and determines what parser should be used for
@@ -21,7 +17,6 @@ class ConfigFile:
Args:
file_path: The path to your configuration file.
- parser: A custom parser you'd like used for your config file.
Raises:
ValueError: If the specified file path does not have an extension
@@ -29,11 +24,7 @@ class ConfigFile:
FileNotFoundError: If the specified file path does not exist.
"""
self.__path = ConfigFilePath(file_path).validate()
-
- if parser is not None and not inspect.isabstract(parser):
- self.__parser = parser(self.__path.contents)
- else:
- self.__parser = self.__path.parser
+ self.__parser = self.__path.parser
@property
def file_path(self) -> Path:
@@ -43,6 +34,15 @@ class ConfigFile:
def original_file_path(self) -> Path:
return Path(self.__path.original_path)
+ def __getitem__(self, key: str):
+ return self.__parser.parsed_content[key]
+
+ def __setitem__(self, key: str, value: Any):
+ self.__parser.parsed_content[key] = value
+
+ def __delitem__(self, key: str):
+ del self.__parser.parsed_content[key]
+
def get(
self,
key: str,