Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 543:491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 01 Jan 2022 18:01:32 +0100 |
| parents | f71d34dda19f |
| children | 325008573bc6 |
comparison
equal
deleted
inserted
replaced
| 542:f71d34dda19f | 543:491413368c7c |
|---|---|
| 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 | 34 from ._speedups import fast_unquote, fast_pathstr2path, _fast_split_ns |
| 35 except ImportError: | 35 except ImportError: |
| 36 fast_unquote = None | 36 fast_unquote = None |
| 37 fast_pathstr2path = None | 37 fast_pathstr2path = None |
| 38 _fast_split_ns = None | |
| 38 | 39 |
| 39 | 40 |
| 40 _MARKER = object() | 41 _MARKER = object() |
| 41 _MISSING = object() | 42 _MISSING = object() |
| 42 | 43 |
| 360 pathstr2path = fast_pathstr2path | 361 pathstr2path = fast_pathstr2path |
| 361 else: | 362 else: |
| 362 pathstr2path = py_pathstr2path | 363 pathstr2path = py_pathstr2path |
| 363 | 364 |
| 364 | 365 |
| 365 def _split_ns(varname): | 366 def _py_split_ns(varname): |
| 366 """Split the variable name string `varname` into the namespace and | 367 """Split the variable name string `varname` into the namespace and |
| 367 the namespace-specific name | 368 the namespace-specific name |
| 368 | 369 |
| 369 :type varname: str | 370 :type varname: str |
| 370 :return: A tuple containing the namespace (or `None`) and the | 371 :return: A tuple containing the namespace (or `None`) and the |
| 371 namespace-specific (variable-)name | 372 namespace-specific (variable-)name |
| 372 :rtype: tuple(str or None, str) | 373 :rtype: tuple(str or None, str) |
| 374 | |
| 375 .. note:: The returned namespace may be an empty string if the namespace | |
| 376 separator is found. | |
| 373 | 377 |
| 374 """ | 378 """ |
| 375 ns, sep, rest = varname.partition(_NS_SEPARATOR) | 379 ns, sep, rest = varname.partition(_NS_SEPARATOR) |
| 376 if sep: | 380 if sep: |
| 377 return (unquote(ns), rest) | 381 return (unquote(ns), rest) |
| 378 else: | 382 else: |
| 379 return (None, ns) | 383 return (None, ns) |
| 384 | |
| 385 | |
| 386 if _fast_split_ns: | |
| 387 _split_ns = _fast_split_ns | |
| 388 else: | |
| 389 _split_ns = _py_split_ns | |
| 380 | 390 |
| 381 | 391 |
| 382 def _split_filters(varname): | 392 def _split_filters(varname): |
| 383 """Split off the filter part from the `varname` string | 393 """Split off the filter part from the `varname` string |
| 384 | 394 |
