Mercurial > hgrepos > Python > libs > ConfigMix
changeset 321:7a0f3c256cf4
FIX: Python2 compatibility: keyword arguments after *args not allowed: use **kwds and manual retrieval with .pop() instead
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Thu, 06 May 2021 11:06:50 +0200 |
| parents | 98490375d90c |
| children | 4aa19e04ff65 |
| files | configmix/config.py |
| diffstat | 1 files changed, 14 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/configmix/config.py Thu May 06 09:45:51 2021 +0200 +++ b/configmix/config.py Thu May 06 11:06:50 2021 +0200 @@ -72,13 +72,15 @@ _DOT = u(b'.') _QUOTE = u(b'%') - def getvarl(self, *names, default=_MARKER, namespace=None): + def getvarl(self, *names, **kwds): """Get a variable where the hierarchy is given in `names` as sequence and the namespace is given in `namespace`. No variable interpolation is done and no filters are applied. """ + default = kwds.pop("default", _MARKER) + namespace = kwds.pop("namespace", None) try: if not namespace: lookupfn = self._lookupvar @@ -110,7 +112,7 @@ varnameparts = (varname,) return self.getvarl(*varnameparts, namespace=varns) - def getvarl_s(self, *names, default=_MARKER, namespace=None): + def getvarl_s(self, *names, **kwds): """Get a variable - including variables from other namespaces. `names` and `namespace` are interpreted as in @@ -121,6 +123,8 @@ For more details see chapter :ref:`variable-interpolation`. """ + default = kwds.pop("default", _MARKER) + namespace = kwds.pop("namespace", None) try: obj = self.getvarl(*names, namespace=namespace) return self.substitute_variables_in_obj(obj) @@ -149,12 +153,12 @@ else: return default - def getintvarl_s(self, *names, default=_MARKER, namespace=None): + def getintvarl_s(self, *names, **kwds): """Get a (possibly substituted) variable and coerce text to a number. """ - s = self.getvarl_s(*names, default=default, namespace=namespace) + s = self.getvarl_s(*names, **kwds) if isinstance(s, self._TEXTTYPE): return int(s, 0) else: @@ -171,12 +175,12 @@ else: return s - def getboolvarl_s(self, *names, default=_MARKER, namespace=None): + def getboolvarl_s(self, *names, **kwds): """Get a (possibly substituted) variable and convert text to a boolean """ - s = self.getvarl_s(*names, default=default, namespace=namespace) + s = self.getvarl_s(*names, **kwds) if isinstance(s, self._TEXTTYPE): sl = s.strip().lower() if sl not in self._BOOL_CVT: @@ -205,12 +209,12 @@ u('0'): False, u('no'): False, u('false'): False, u('off'): False } - def getfloatvarl_s(self, *names, default=_MARKER, namespace=None): + def getfloatvarl_s(self, *names, **kwds): """Get a (possibly substituted) variable and convert text to a float """ - s = self.getvarl_s(*names, default=default, namespace=namespace) + s = self.getvarl_s(*names, **kwds) if isinstance(s, self._TEXTTYPE): return float(s) else: @@ -241,12 +245,13 @@ else: return (nameparts[0].rstrip(), nameparts[1:], ) - def _lookupvar(self, *names, default=_MARKER): + def _lookupvar(self, *names, **kwds): """Lookup a variable within a hierarchy. If no default is given an unexisting `name` 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:]:
