Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/config.py @ 542:f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
This is currently for Python 3.5+.
It is tested with Python 3.7 and Python3.8 (FreeBSD 12.2 amd64, LLVM 10.0.1).
A build for the stable API ("abi3") fails because PyUnicode_New() is currently
not in the stable API.
Also includes are extended tests for unquote() and pathstr2path().
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 31 Dec 2021 21:24:16 +0100 |
| parents | 25b61f0a1958 |
| children | 491413368c7c |
line wrap: on
line diff
--- a/configmix/config.py Wed Dec 29 13:33:11 2021 +0100 +++ b/configmix/config.py Fri Dec 31 21:24:16 2021 +0100 @@ -30,6 +30,11 @@ from .variables import lookup_varns, lookup_filter from .compat import u, uchr, n, str_and_u, PY2 from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER +try: + from ._speedups import fast_unquote, fast_pathstr2path +except ImportError: + fast_unquote = None + fast_pathstr2path = None _MARKER = object() @@ -280,7 +285,7 @@ return s -def unquote(s): +def py_unquote(s): """Unquote the content of `s`: handle all patterns ``%xNN``, ``%uNNNN`` or ``%UNNNNNNNN``. @@ -317,7 +322,13 @@ return _EMPTY_STR.join(res) -def pathstr2path(varname): +if fast_unquote: + unquote = fast_unquote +else: + unquote = py_unquote + + +def py_pathstr2path(varname): """Parse a dot-separated path string `varname` into a tuple of unquoted path items @@ -345,6 +356,12 @@ return tuple() +if fast_pathstr2path: + pathstr2path = fast_pathstr2path +else: + pathstr2path = py_pathstr2path + + def _split_ns(varname): """Split the variable name string `varname` into the namespace and the namespace-specific name @@ -355,7 +372,6 @@ :rtype: tuple(str or None, str) """ - ns, sep, rest = varname.partition(_NS_SEPARATOR) if sep: return (unquote(ns), rest) @@ -366,7 +382,7 @@ def _split_filters(varname): """Split off the filter part from the `varname` string - :type varname: str + :type varname: str :return: The tuple of the variable name without the filters and a list of filters :rtype: tuple(str, list)
