Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 469:02b210a2b022
Docs
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 16 Dec 2021 09:19:50 +0100 |
| parents | 95df1a10259a |
| children | fa5b800055e4 |
comparison
equal
deleted
inserted
replaced
| 468:95df1a10259a | 469:02b210a2b022 |
|---|---|
| 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 | 240 |
| 241 def __getitem__(self, key): | 241 def __getitem__(self, key): |
| 242 """Mapping interface that forwards to :meth:`~.getvarl_s` | 242 """Mapping and list interface that forwards to :meth:`~.getvarl_s` |
| 243 | 243 |
| 244 """ | 244 """ |
| 245 if isinstance(key, (tuple, list)): | 245 if isinstance(key, (tuple, list)): |
| 246 return self.getvarl_s(*key) | 246 return self.getvarl_s(*key) |
| 247 else: | 247 else: |
| 255 return self.getvarl_s(*key, default=default) | 255 return self.getvarl_s(*key, default=default) |
| 256 else: | 256 else: |
| 257 return self.getvarl_s(key, default=default) | 257 return self.getvarl_s(key, default=default) |
| 258 | 258 |
| 259 def __contains__(self, key): | 259 def __contains__(self, key): |
| 260 """Containment test""" | |
| 260 if isinstance(key, (tuple, list)): | 261 if isinstance(key, (tuple, list)): |
| 261 # No namespace and quoting support here | 262 # No namespace and quoting support here |
| 262 try: | 263 try: |
| 263 self._lookupvar(*key) | 264 self._lookupvar(*key) |
| 264 except KeyError: | 265 except KeyError: |
| 848 raise KeyError( | 849 raise KeyError( |
| 849 "base key path %r not available in the new base" | 850 "base key path %r not available in the new base" |
| 850 % (self._path, )) | 851 % (self._path, )) |
| 851 | 852 |
| 852 def __getattr__(self, name): | 853 def __getattr__(self, name): |
| 854 """Attribute-style access. | |
| 855 | |
| 856 Result values are interpolated (i.e. forwarded to | |
| 857 :meth:`~.getvarl_s`) | |
| 858 | |
| 859 """ | |
| 853 try: | 860 try: |
| 854 v = self._base.getvarl_s(*(self._path + (name, ))) | 861 v = self._base.getvarl_s(*(self._path + (name, ))) |
| 855 except KeyError: | 862 except KeyError: |
| 856 raise AttributeError("%s has no attribute %r" % (type(self), name)) | 863 raise AttributeError("%s has no attribute %r" % (type(self), name)) |
| 857 else: | 864 else: |
| 860 return _AttributeDict(v) | 867 return _AttributeDict(v) |
| 861 else: | 868 else: |
| 862 return v | 869 return v |
| 863 | 870 |
| 864 def __getitem__(self, key): | 871 def __getitem__(self, key): |
| 865 """Mapping interface that forwards to :meth:`~.getvarl_s` | 872 """Mapping and list interface that forwards to :meth:`~.getvarl_s` |
| 866 | 873 |
| 867 """ | 874 """ |
| 868 if isinstance(key, tuple): | 875 if isinstance(key, tuple): |
| 869 return self._base.getvarl_s(*(self._path + key)) | 876 return self._base.getvarl_s(*(self._path + key)) |
| 870 elif isinstance(key, list): | 877 elif isinstance(key, list): |
| 879 return self._base.get(self._path + tuple(key), default=default) | 886 return self._base.get(self._path + tuple(key), default=default) |
| 880 else: | 887 else: |
| 881 return self._base.get(self._path + (key, ), default=default) | 888 return self._base.get(self._path + (key, ), default=default) |
| 882 | 889 |
| 883 def __contains__(self, key): | 890 def __contains__(self, key): |
| 891 """Containment support for containers""" | |
| 884 if isinstance(key, tuple): | 892 if isinstance(key, tuple): |
| 885 return (self._path + key) in self._base | 893 return (self._path + key) in self._base |
| 886 elif isinstance(key, list): | 894 elif isinstance(key, list): |
| 887 return (self._path + tuple(key)) in self._base | 895 return (self._path + tuple(key)) in self._base |
| 888 else: | 896 else: |
| 939 def getfirstvar_s(self, *varnames, **kwds): | 947 def getfirstvar_s(self, *varnames, **kwds): |
| 940 real_varnames = [self._pathstr + vn for vn in varnames] | 948 real_varnames = [self._pathstr + vn for vn in varnames] |
| 941 return self._base.getfirstvar_s(*real_varnames, **kwds) | 949 return self._base.getfirstvar_s(*real_varnames, **kwds) |
| 942 | 950 |
| 943 def __iter__(self): | 951 def __iter__(self): |
| 952 """Iteration support for containers""" | |
| 944 return iter(self._base.getvarl_s(*self._path)) | 953 return iter(self._base.getvarl_s(*self._path)) |
| 945 | 954 |
| 946 def __len__(self): | 955 def __len__(self): |
| 956 """Length support for containers""" | |
| 947 return len(self._base.getvarl(*self._path)) | 957 return len(self._base.getvarl(*self._path)) |
| 948 | 958 |
| 949 if PY2: | 959 if PY2: |
| 950 | 960 |
| 951 def __nonzero__(self): | 961 def __nonzero__(self): |
| 962 """Map- and list-style evaluation in boolean context""" | |
| 952 return bool(self._base.getvarl_s(*self._path)) | 963 return bool(self._base.getvarl_s(*self._path)) |
| 953 | 964 |
| 954 else: | 965 else: |
| 955 | 966 |
| 956 def __bool__(self): | 967 def __bool__(self): |
| 968 """Map- and list-style evaluation in boolean context""" | |
| 957 return bool(self._base.getvarl_s(*self._path)) | 969 return bool(self._base.getvarl_s(*self._path)) |
| 958 | 970 |
| 959 def jailed(self, rootpath=None, root=None, bind_root=True): | 971 def jailed(self, rootpath=None, root=None, bind_root=True): |
| 960 """Return a "jailed" configuration that effectively is a | 972 """Return a "jailed" configuration that effectively is a |
| 961 subjail of the current jail | 973 subjail of the current jail |
