summaryrefslogtreecommitdiff
path: root/talerbank/talerconfig.py
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2017-12-07 15:22:12 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2017-12-07 15:22:12 +0100
commitb2ea43b7ccba2f5dd191185f7eb86edff69d9137 (patch)
treebad1affb8304cb0e926fe344e1e370aabe3b4db9 /talerbank/talerconfig.py
parent4efff7788f052cfdd2949af9198eb2c18a4cd4e8 (diff)
downloadbank-b2ea43b7ccba2f5dd191185f7eb86edff69d9137.tar.gz
bank-b2ea43b7ccba2f5dd191185f7eb86edff69d9137.tar.bz2
bank-b2ea43b7ccba2f5dd191185f7eb86edff69d9137.zip
resolving conflict between mypy and Python itself
Diffstat (limited to 'talerbank/talerconfig.py')
-rw-r--r--talerbank/talerconfig.py57
1 files changed, 29 insertions, 28 deletions
diff --git a/talerbank/talerconfig.py b/talerbank/talerconfig.py
index 41ebf44..5d42adc 100644
--- a/talerbank/talerconfig.py
+++ b/talerbank/talerconfig.py
@@ -93,33 +93,8 @@ def expand(var: str, getter: Callable[[str], str]) -> str:
return result + var[pos:]
-class OptionDict(collections.defaultdict):
- def __init__(self, config: SectionDict, section_name: str) -> None:
- self.config = weakref.ref(config)
- self.section_name = section_name
- super().__init__()
- def __missing__(self, key: str) -> Entry:
- entry = Entry(self.config(), self.section_name, key)
- self[key] = entry
- return entry
- def __getitem__(self, chunk: str) -> Entry:
- return super().__getitem__(chunk.lower())
- def __setitem__(self, chunk: str, value: Entry) -> None:
- super().__setitem__(chunk.lower(), value)
-
-
-class SectionDict(collections.defaultdict):
- def __missing__(self, key):
- value = OptionDict(self, key)
- self[key] = value
- return value
- def __getitem__(self, chunk: str) -> OptionDict:
- return super().__getitem__(chunk.lower())
- def __setitem__(self, chunk: str, value: OptionDict) -> None:
- super().__setitem__(chunk.lower(), value)
-
class Entry:
- def __init__(self, config: SectionDict, section: str, option: str, **kwargs) -> None:
+ def __init__(self, config, section: str, option: str, **kwargs) -> None:
self.value = kwargs.get("value")
self.filename = kwargs.get("filename")
self.lineno = kwargs.get("lineno")
@@ -180,6 +155,32 @@ class Entry:
return "%s:%s" % (self.filename, self.lineno)
+class OptionDict(collections.defaultdict):
+ def __init__(self, config, section_name: str) -> None:
+ self.config = weakref.ref(config)
+ self.section_name = section_name
+ super().__init__()
+ def __missing__(self, key: str) -> Entry:
+ entry = Entry(self.config(), self.section_name, key)
+ self[key] = entry
+ return entry
+ def __getitem__(self, chunk: str) -> Entry:
+ return super().__getitem__(chunk.lower())
+ def __setitem__(self, chunk: str, value: Entry) -> None:
+ super().__setitem__(chunk.lower(), value)
+
+
+class SectionDict(collections.defaultdict):
+ def __missing__(self, key):
+ value = OptionDict(self, key)
+ self[key] = value
+ return value
+ def __getitem__(self, chunk: str) -> OptionDict:
+ return super().__getitem__(chunk.lower())
+ def __setitem__(self, chunk: str, value: OptionDict) -> None:
+ super().__setitem__(chunk.lower(), value)
+
+
class TalerConfig:
"""
One loaded taler configuration, including base configuration
@@ -194,7 +195,7 @@ class TalerConfig:
# defaults != config file: the first is the 'base'
# whereas the second overrides things from the first.
@staticmethod
- def from_file(filename=None, load_defaults=True) -> TalerConfig:
+ def from_file(filename=None, load_defaults=True):
cfg = TalerConfig()
if filename is None:
xdg = os.environ.get("XDG_CONFIG_HOME")
@@ -237,7 +238,7 @@ class TalerConfig:
LOGGER.warning("no base directory found")
@staticmethod
- def from_env(*args, **kwargs) -> TalerConfig:
+ def from_env(*args, **kwargs):
"""
Load configuration from environment variable TALER_CONFIG_FILE
or from default location if the variable is not set.