Mercurial > hgrepos > Python > libs > ConfigMix
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 549:84657447ab39 | 550:79db28e879f8 |
|---|---|
| 29 | 29 |
| 30 from .variables import lookup_varns, lookup_filter | 30 from .variables import lookup_varns, lookup_filter |
| 31 from .compat import u, uchr, n, str_and_u, PY2 | 31 from .compat import u, uchr, n, str_and_u, PY2 |
| 32 from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER | 32 from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER |
| 33 try: | 33 try: |
| 34 from ._speedups import fast_unquote, fast_pathstr2path, _fast_split_ns | 34 from ._speedups import (fast_unquote, fast_quote, fast_pathstr2path, |
| 35 _fast_split_ns) | |
| 35 except ImportError: | 36 except ImportError: |
| 36 fast_unquote = None | 37 fast_unquote = None |
| 38 fast_quote = None | |
| 37 fast_pathstr2path = None | 39 fast_pathstr2path = None |
| 38 _fast_split_ns = None | 40 _fast_split_ns = None |
| 39 | 41 |
| 40 | 42 |
| 41 _MARKER = object() | 43 _MARKER = object() |
| 255 """Mostly used configuration key characters that do not need any quoting | 257 """Mostly used configuration key characters that do not need any quoting |
| 256 | 258 |
| 257 """ | 259 """ |
| 258 | 260 |
| 259 | 261 |
| 260 def quote(s): | 262 def py_quote(s): |
| 261 """Replace important special characters in string `s` by replacing | 263 """Replace important special characters in string `s` by replacing |
| 262 them with ``%xNN`` where `NN` are the two hexadecimal digits of the | 264 them with ``%xNN`` where `NN` are the two hexadecimal digits of the |
| 263 characters unicode codepoint value. | 265 characters unicode codepoint value. |
| 264 | 266 |
| 265 Handled are the important special chars: ``%``, ``.``, ``:``, | 267 Handled are the important special chars: ``%``, ``.``, ``:``, |
| 282 s = s.translate(_QUOTE_MAP) | 284 s = s.translate(_QUOTE_MAP) |
| 283 if re_encode: | 285 if re_encode: |
| 284 return s.encode("latin1") | 286 return s.encode("latin1") |
| 285 else: | 287 else: |
| 286 return s | 288 return s |
| 289 | |
| 290 | |
| 291 if fast_quote: | |
| 292 quote = fast_quote | |
| 293 else: | |
| 294 quote = py_quote | |
| 287 | 295 |
| 288 | 296 |
| 289 def py_unquote(s): | 297 def py_unquote(s): |
| 290 """Unquote the content of `s`: handle all patterns ``%xNN``, | 298 """Unquote the content of `s`: handle all patterns ``%xNN``, |
| 291 ``%uNNNN`` or ``%UNNNNNNNN``. | 299 ``%uNNNN`` or ``%UNNNNNNNN``. |
