# HG changeset patch # User Franz Glasner # Date 1640715748 -3600 # Node ID 33856ae1cc0beb498cdb6a775a6e3eef7cb336ce # Parent 9546d38cd3f83053e733a889f400785cc8686f55 _split_ns() and _split_filters() are now module-globals diff -r 9546d38cd3f8 -r 33856ae1cc0b configmix/config.py --- a/configmix/config.py Tue Dec 28 17:28:19 2021 +0100 +++ b/configmix/config.py Tue Dec 28 19:22:28 2021 +0100 @@ -345,6 +345,27 @@ return tuple() +def _split_ns(s): + ns, sep, rest = s.partition(_NS_SEPARATOR) + if sep: + return (unquote(ns), rest) + else: + return (None, ns) + + +def _split_filters(s): + name, sep, filters = s.partition(_FILTER_SEPARATOR) + if sep: + filters = filters.strip() + if filters: + return (name.rstrip(), + filters.split(_FILTER_SEPARATOR)) + else: + return (name.rstrip(), []) + else: + return (name, []) + + class Configuration(CoercingMethodsMixin, _AttributeDict): """The configuration dictionary with attribute support or @@ -523,7 +544,7 @@ See also :func:`.quote`. """ - varns, varname = self._split_ns(varname) + varns, varname = _split_ns(varname) if not varns: return self.getvarl(*pathstr2path(varname), default=default) else: @@ -636,7 +657,7 @@ For more details see chapter :ref:`variable-interpolation`. """ - varns, varname = self._split_ns(varname) + varns, varname = _split_ns(varname) try: if not varns: return self.substitute_variables_in_obj( @@ -659,7 +680,7 @@ Currently used by :meth:`~.interpolate_variables`. """ - varns, varname = self._split_ns(varname) + varns, varname = _split_ns(varname) if not varns: # no namespace -> cacheable return ( @@ -694,25 +715,6 @@ else: return default - def _split_ns(self, s): - ns, sep, rest = s.partition(_NS_SEPARATOR) - if sep: - return (unquote(ns), rest) - else: - return (None, ns) - - def _split_filters(self, s): - name, sep, filters = s.partition(_FILTER_SEPARATOR) - if sep: - filters = filters.strip() - if filters: - return (name.rstrip(), - filters.split(_FILTER_SEPARATOR)) - else: - return (name.rstrip(), []) - else: - return (name, []) - def _lookupvar(self, *path): """Lookup a variable within a hierarchy. @@ -840,7 +842,7 @@ if end < 0: rest = start break - varname, filters = self._split_filters( + varname, filters = _split_filters( s[start+2:end]) # noqa: E226 try: varvalue, cacheable = self._getvar_s_with_cache_info(varname) @@ -922,7 +924,7 @@ raise TypeError("`rootpath' must be a list or a tuple") if root is not None: # convert to path - varns, varname = self._split_ns(root) + varns, varname = _split_ns(root) if varns: raise ValueError( "jailed configurations do not support namespaces") @@ -1142,7 +1144,7 @@ raise TypeError("`rootpath' must be a list or a tuple") if root is not None: # convert to path - varns, varname = self._base._split_ns(root) + varns, varname = _split_ns(root) if varns: raise ValueError( "sub-jails do not support namespaces")