Mercurial > hgrepos > Python > libs > ConfigMix
changeset 382:24db29162d09
Renamed "names" arguments into the more proper "path"
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 10 Nov 2021 01:42:15 +0100 |
| parents | fe3dfd687621 |
| children | 5c72da46b8ae |
| files | configmix/config.py |
| diffstat | 1 files changed, 20 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/configmix/config.py Wed Nov 10 01:37:36 2021 +0100 +++ b/configmix/config.py Wed Nov 10 01:42:15 2021 +0100 @@ -73,13 +73,13 @@ _QUOTE = u(b'%') _COMMENT = u(b'#') - def getvarl(self, *names, **kwds): - """Get a variable where the hierarchy is given in `names` as sequence + def getvarl(self, *path, **kwds): + """Get a variable where the hierarchy is given in `path` as sequence and the namespace is given in the `namespace` keyword argument. No variable interpolation is done and no filters are applied. - Quoting of `names` and `namespace` is *not* needed and wrong. + Quoting of `path` and `namespace` is *not* needed and wrong. """ default = kwds.pop("default", _MARKER) @@ -92,10 +92,10 @@ lookupfn = self._lookupref else: lookupfn = lookup_varns(namespace) - varvalue = lookupfn(*names) + varvalue = lookupfn(*path) except KeyError: if default is _MARKER: - raise KeyError("Variable %r not found" % (names,)) + raise KeyError("Variable %r not found" % (path,)) else: return default else: @@ -171,10 +171,10 @@ else: return default - def getvarl_s(self, *names, **kwds): + def getvarl_s(self, *path, **kwds): """Get a variable - including variables from other namespaces. - `names` and `namespace` are interpreted as in + `path` and `namespace` are interpreted as in :meth:`.getvarl`. But variables will be interpolated recursively within the variable values and filters are applied. @@ -185,7 +185,7 @@ default = kwds.pop("default", _MARKER) namespace = kwds.pop("namespace", None) try: - obj = self.getvarl(*names, namespace=namespace) + obj = self.getvarl(*path, namespace=namespace) return self.substitute_variables_in_obj(obj) except KeyError: if default is _MARKER: @@ -264,12 +264,12 @@ else: return default - def getintvarl_s(self, *names, **kwds): + def getintvarl_s(self, *path, **kwds): """Get a (possibly substituted) variable and coerce text to a number. """ - s = self.getvarl_s(*names, **kwds) + s = self.getvarl_s(*path, **kwds) if isinstance(s, self._TEXTTYPE): return int(s, 0) else: @@ -297,12 +297,12 @@ else: return s - def getboolvarl_s(self, *names, **kwds): + def getboolvarl_s(self, *path, **kwds): """Get a (possibly substituted) variable and convert text to a boolean """ - s = self.getvarl_s(*names, **kwds) + s = self.getvarl_s(*path, **kwds) if isinstance(s, self._TEXTTYPE): sl = s.strip().lower() if sl not in self._BOOL_CVT: @@ -345,12 +345,12 @@ u('0'): False, u('no'): False, u('false'): False, u('off'): False } - def getfloatvarl_s(self, *names, **kwds): + def getfloatvarl_s(self, *path, **kwds): """Get a (possibly substituted) variable and convert text to a float """ - s = self.getvarl_s(*names, **kwds) + s = self.getvarl_s(*path, **kwds) if isinstance(s, self._TEXTTYPE): return float(s) else: @@ -381,25 +381,25 @@ else: return (nameparts[0].rstrip(), nameparts[1:], ) - def _lookupvar(self, *names, **kwds): + def _lookupvar(self, *path, **kwds): """Lookup a variable within a hierarchy. - If no default is given an unexisting `name` raises a `KeyError` + If no default is given an unexisting `path` raises a `KeyError` else `default` is returned. """ default = kwds.pop("default", _MARKER) try: - v = self.expand_if_reference(self[names[0]]) - for p in names[1:]: + v = self.expand_if_reference(self[path[0]]) + for p in path[1:]: v = self.expand_if_reference(v[p]) except TypeError: raise KeyError( "Configuration variable %r not found" - "(missing intermediate keys?)" % (names,)) + "(missing intermediate keys?)" % (path,)) except KeyError: if default is _MARKER: raise KeyError( - "Configuration variable %r not found" % (names,)) + "Configuration variable %r not found" % (path,)) else: return default return v
