Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 552:39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
This is needed as precondition for implementation interpolate_variables in
C also.
Currently the speedup is not measurable but it does not hurt also.
Also provide some unit-tests for _split_filters().
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 02 Jan 2022 20:40:09 +0100 |
| parents | 4c968c5cfce6 |
| children | 9d2bd411f5c5 |
comparison
equal
deleted
inserted
replaced
| 551:4c968c5cfce6 | 552:39e5d07d8dbc |
|---|---|
| 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_quote, fast_pathstr2path, | 34 from ._speedups import (fast_unquote, fast_quote, fast_pathstr2path, |
| 35 _fast_split_ns) | 35 _fast_split_ns, _fast_split_filters) |
| 36 except ImportError: | 36 except ImportError: |
| 37 fast_unquote = None | 37 fast_unquote = None |
| 38 fast_quote = None | 38 fast_quote = None |
| 39 fast_pathstr2path = None | 39 fast_pathstr2path = None |
| 40 _fast_split_ns = None | 40 _fast_split_ns = None |
| 41 _fast_split_filters = None | |
| 41 | 42 |
| 42 | 43 |
| 43 _MARKER = object() | 44 _MARKER = object() |
| 44 _MISSING = object() | 45 _MISSING = object() |
| 45 | 46 |
| 395 _split_ns = _fast_split_ns | 396 _split_ns = _fast_split_ns |
| 396 else: | 397 else: |
| 397 _split_ns = _py_split_ns | 398 _split_ns = _py_split_ns |
| 398 | 399 |
| 399 | 400 |
| 400 def _split_filters(varname): | 401 def _py_split_filters(varname): |
| 401 """Split off the filter part from the `varname` string | 402 """Split off the filter part from the `varname` string |
| 402 | 403 |
| 403 :type varname: str | 404 :type varname: str |
| 404 :return: The tuple of the variable name without the filters and a list | 405 :return: The tuple of the variable name without the filters and a list |
| 405 of filters | 406 of filters |
| 414 filters.split(_FILTER_SEPARATOR)) | 415 filters.split(_FILTER_SEPARATOR)) |
| 415 else: | 416 else: |
| 416 return (name.rstrip(), []) | 417 return (name.rstrip(), []) |
| 417 else: | 418 else: |
| 418 return (name, []) | 419 return (name, []) |
| 420 | |
| 421 | |
| 422 if _fast_split_filters: | |
| 423 _split_filters = _fast_split_filters | |
| 424 else: | |
| 425 _split_filters = _py_split_filters | |
| 419 | 426 |
| 420 | 427 |
| 421 class Configuration(CoercingMethodsMixin, _AttributeDict): | 428 class Configuration(CoercingMethodsMixin, _AttributeDict): |
| 422 | 429 |
| 423 """The configuration dictionary with attribute support or | 430 """The configuration dictionary with attribute support or |
