Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 437:bbc5b64e137a
- Dict-level access to a configuration key now does variable interpolation.
- Basic dict-level access for jailed configurations
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 10 Dec 2021 01:33:37 +0100 |
| parents | b96f49c9c76b |
| children | 37424d1f8dcf |
comparison
equal
deleted
inserted
replaced
| 436:3ae097e04879 | 437:bbc5b64e137a |
|---|---|
| 235 _QUOTE = u(b'%') | 235 _QUOTE = u(b'%') |
| 236 _COMMENT = u(b'#') | 236 _COMMENT = u(b'#') |
| 237 | 237 |
| 238 is_jail = False | 238 is_jail = False |
| 239 """Flag to show that this is not a jail for another configuration""" | 239 """Flag to show that this is not a jail for another configuration""" |
| 240 | |
| 241 def __getitem__(self, key): | |
| 242 """Mapping interface that forwards to :meth:`~.getvarl_s` | |
| 243 | |
| 244 """ | |
| 245 if isinstance(key, (tuple, list)): | |
| 246 return self.getvarl_s(*key) | |
| 247 else: | |
| 248 return self.getvarl_s(key) | |
| 240 | 249 |
| 241 def getvarl(self, *path, **kwds): | 250 def getvarl(self, *path, **kwds): |
| 242 """Get a variable where the hierarchy is given in `path` as sequence | 251 """Get a variable where the hierarchy is given in `path` as sequence |
| 243 and the namespace is given in the `namespace` keyword argument. | 252 and the namespace is given in the `namespace` keyword argument. |
| 244 | 253 |
| 511 """ | 520 """ |
| 512 default = kwds.pop("default", _MARKER) | 521 default = kwds.pop("default", _MARKER) |
| 513 if not path: | 522 if not path: |
| 514 return self | 523 return self |
| 515 try: | 524 try: |
| 516 v = self.expand_if_reference(self[path[0]]) | 525 # v = self.expand_if_reference(self[path[0]]) |
| 526 v = self.expand_if_reference(super(Configuration, self).__getitem__(path[0])) | |
| 517 for p in path[1:]: | 527 for p in path[1:]: |
| 518 v = self.expand_if_reference(v[p]) | 528 v = self.expand_if_reference(v[p]) |
| 519 except TypeError: | 529 except TypeError: |
| 520 raise KeyError( | 530 raise KeyError( |
| 521 "Configuration variable %r not found" | 531 "Configuration variable %r not found" |
| 806 # degenerated case if `self._path` is empty. | 816 # degenerated case if `self._path` is empty. |
| 807 # | 817 # |
| 808 if self._path: | 818 if self._path: |
| 809 new_base.getvarl(*self._path) | 819 new_base.getvarl(*self._path) |
| 810 | 820 |
| 821 def __getitem__(self, key): | |
| 822 """Mapping interface that forwards to :meth:`~.getvarl_s` | |
| 823 | |
| 824 """ | |
| 825 if isinstance(key, (tuple, list)): | |
| 826 return self.getvarl_s(*key) | |
| 827 else: | |
| 828 return self.getvarl_s(key) | |
| 829 | |
| 811 def getvarl(self, *path, **kwds): | 830 def getvarl(self, *path, **kwds): |
| 812 return self._base.getvarl(*(self._path + path), **kwds) | 831 return self._base.getvarl(*(self._path + path), **kwds) |
| 813 | 832 |
| 814 def getkeysl(self, *path, **kwds): | 833 def getkeysl(self, *path, **kwds): |
| 815 for k in self._base.getkeysl(*(self._path + path), **kwds): | 834 for k in self._base.getkeysl(*(self._path + path), **kwds): |
