changeset 540:33856ae1cc0b

_split_ns() and _split_filters() are now module-globals
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 28 Dec 2021 19:22:28 +0100
parents 9546d38cd3f8
children 25b61f0a1958
files configmix/config.py
diffstat 1 files changed, 27 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- 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")