diff configmix/config.py @ 550:79db28e879f8

Provide a C-implementation of configmix.config.quote() also: fast_quote
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 02 Jan 2022 02:04:07 +0100
parents 325008573bc6
children 4c968c5cfce6
line wrap: on
line diff
--- a/configmix/config.py	Sun Jan 02 01:00:10 2022 +0100
+++ b/configmix/config.py	Sun Jan 02 02:04:07 2022 +0100
@@ -31,9 +31,11 @@
 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, _fast_split_ns
+    from ._speedups import (fast_unquote, fast_quote, fast_pathstr2path,
+                            _fast_split_ns)
 except ImportError:
     fast_unquote = None
+    fast_quote = None
     fast_pathstr2path = None
     _fast_split_ns = None
 
@@ -257,7 +259,7 @@
 """
 
 
-def quote(s):
+def py_quote(s):
     """Replace important special characters in string `s` by replacing
     them with ``%xNN`` where `NN` are the two hexadecimal digits of the
     characters unicode codepoint value.
@@ -286,6 +288,12 @@
         return s
 
 
+if fast_quote:
+    quote = fast_quote
+else:
+    quote = py_quote
+
+
 def py_unquote(s):
     """Unquote the content of `s`: handle all patterns ``%xNN``,
     ``%uNNNN`` or ``%UNNNNNNNN``.