diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-11-06 20:40:42 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-11-06 20:53:55 +0300 |
commit | 75ee161b6eb64cf19c8a9718d15047443f3e4ebe (patch) | |
tree | ccebc9cbd2709ad13a14ec00372fdcfe9226cd9f /src/home/config | |
parent | 28c67c4510a3bee574b4077be35147dba257c8f7 (diff) |
inverter_bot: refactor and introduce new functions
Diffstat (limited to 'src/home/config')
-rw-r--r-- | src/home/config/config.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/home/config/config.py b/src/home/config/config.py index 7d18f99..0c0e944 100644 --- a/src/home/config/config.py +++ b/src/home/config/config.py @@ -105,6 +105,19 @@ class ConfigStore: def __contains__(self, key): return key in self.data + def get(self, key: str, default=None): + cur = self.data + pts = key.split('.') + for i in range(len(pts)): + k = pts[i] + if i < len(pts)-1: + if k not in cur: + raise KeyError(f'key {k} not found') + else: + return cur[k] if k in cur else default + cur = self.data[k] + raise KeyError(f'option {key} not found') + def items(self): return self.data.items() |