aboutsummaryrefslogtreecommitdiffstats
path: root/config_file
diff options
context:
space:
mode:
Diffstat (limited to 'config_file')
-rw-r--r--config_file/config_file.py18
-rw-r--r--config_file/ini_parser.py8
2 files changed, 22 insertions, 4 deletions
diff --git a/config_file/config_file.py b/config_file/config_file.py
index 934c198..18f3e0f 100644
--- a/config_file/config_file.py
+++ b/config_file/config_file.py
@@ -34,15 +34,24 @@ class ConfigFile:
def original_path(self) -> Path:
return Path(self.__path.original_path)
- def __getitem__(self, key: str):
+ def __getitem__(self, key: str) -> Any:
return self.__parser.parsed_content[key]
- def __setitem__(self, key: str, value: Any):
+ def __setitem__(self, key: str, value: Any) -> None:
self.__parser.parsed_content[key] = value
- def __delitem__(self, key: str):
+ def __delitem__(self, key: str) -> None:
del self.__parser.parsed_content[key]
+ def __contains__(self, key: str) -> bool:
+ return self.has(key)
+
+ def __str__(self) -> str:
+ return self.stringify()
+
+ def __repr__(self) -> str:
+ return f"{self.path}\n\n{self.stringify()}"
+
def get(
self,
key: str,
@@ -122,6 +131,9 @@ class ConfigFile:
Returns:
The internal representation of the file
that has been read in converted to a string.
+
+ Depreciated:
+ Use str() on the ConfigFile object instead.
"""
return self.__parser.stringify()
diff --git a/config_file/ini_parser.py b/config_file/ini_parser.py
index d6905a9..0048288 100644
--- a/config_file/ini_parser.py
+++ b/config_file/ini_parser.py
@@ -1,6 +1,6 @@
import configparser
from io import StringIO
-from typing import Type
+from typing import Type, Any
from .base_parser import BaseParser
@@ -36,3 +36,9 @@ class IniParser(BaseParser):
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)
+ )