Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 448:b95c12781497
Attribute-style access for jailed configurations
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 11 Dec 2021 19:56:35 +0100 |
| parents | 23941c014130 |
| children | 5864977bb44f |
comparison
equal
deleted
inserted
replaced
| 447:4505ef8a1b56 | 448:b95c12781497 |
|---|---|
| 845 # degenerated case if `self._path` is empty. | 845 # degenerated case if `self._path` is empty. |
| 846 # | 846 # |
| 847 if self._path: | 847 if self._path: |
| 848 new_base.getvarl(*self._path) | 848 new_base.getvarl(*self._path) |
| 849 | 849 |
| 850 def __getattr__(self, name): | |
| 851 try: | |
| 852 v = self._base.getvarl_s(*(self._path + (name, ))) | |
| 853 except KeyError: | |
| 854 raise AttributeError("%s has no attribute %r" % (type(self), name)) | |
| 855 else: | |
| 856 # Wrap a dict into another dict with attribute access support | |
| 857 if isinstance(v, dict): | |
| 858 return _AttributeDict(v) | |
| 859 else: | |
| 860 return v | |
| 861 | |
| 850 def __getitem__(self, key): | 862 def __getitem__(self, key): |
| 851 """Mapping interface that forwards to :meth:`~.getvarl_s` | 863 """Mapping interface that forwards to :meth:`~.getvarl_s` |
| 852 | 864 |
| 853 """ | 865 """ |
| 854 if isinstance(key, tuple): | 866 if isinstance(key, tuple): |
