diff options
author | Devaev Maxim <[email protected]> | 2019-04-01 10:30:30 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-04-01 10:30:30 +0300 |
commit | 73e04b71ed55a46c939f12548b31746617af2bca (patch) | |
tree | 8f8c46e38378e7b47214afdc7cb438462971cf7c /kvmd/yamlconf | |
parent | 70e526b7739349773c6203e7744370f19c465d57 (diff) |
modular auth
Diffstat (limited to 'kvmd/yamlconf')
-rw-r--r-- | kvmd/yamlconf/__init__.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/kvmd/yamlconf/__init__.py b/kvmd/yamlconf/__init__.py index ef329082..4c15fee1 100644 --- a/kvmd/yamlconf/__init__.py +++ b/kvmd/yamlconf/__init__.py @@ -66,12 +66,15 @@ class Section(dict): dict.__init__(self) self.__meta: Dict[str, Dict[str, Any]] = {} - def _unpack_renamed(self) -> Dict[str, Any]: + def _unpack_renamed(self, _section: Optional["Section"]=None) -> Dict[str, Any]: + if _section is None: + _section = self unpacked: Dict[str, Any] = {} - for (key, value) in self.items(): - assert not isinstance(value, Section), (key, value) - key = (self.__meta[key]["rename"] or key) - unpacked[key] = value + for (key, value) in _section.items(): + if isinstance(value, Section): + unpacked[key] = value._unpack_renamed() # pylint: disable=protected-access + else: # Option + unpacked[_section._get_rename(key)] = value # pylint: disable=protected-access return unpacked def _set_meta(self, key: str, default: Any, help: str, rename: str) -> None: # pylint: disable=redefined-builtin @@ -87,6 +90,9 @@ class Section(dict): def _get_help(self, key: str) -> str: return self.__meta[key]["help"] + def _get_rename(self, key: str) -> str: + return (self.__meta[key]["rename"] or key) + def __getattribute__(self, key: str) -> Any: if key in self: return self[key] |