Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/config.py @ 554:36d7aa000435
Implement a C-version of Configuration.interpolate_variables
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 03 Jan 2022 00:11:41 +0100 |
| parents | 9d2bd411f5c5 |
| children | f454889e41fa |
line wrap: on
line diff
--- a/configmix/config.py Sun Jan 02 20:43:24 2022 +0100 +++ b/configmix/config.py Mon Jan 03 00:11:41 2022 +0100 @@ -32,13 +32,17 @@ from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER try: from ._speedups import (fast_unquote, fast_quote, fast_pathstr2path, - _fast_split_ns, _fast_split_filters) + _fast_split_ns, _fast_split_filters, + _fast_interpolate_variables, + _sync_MISSING) except ImportError: fast_unquote = None fast_quote = None fast_pathstr2path = None _fast_split_ns = None _fast_split_filters = None + _fast_interpolate_variables = None + _sync_MISSING = None _MARKER = object() @@ -873,7 +877,7 @@ else: return obj - def interpolate_variables(self, s): + def py_interpolate_variables(self, s): """Expand all variables in the single string `s`""" len_s = len(s) if len_s < 4: @@ -943,6 +947,18 @@ self.__interpolation_cache[s] = res return res + if _fast_interpolate_variables: + + def fast_interpolate_variables(self, s): + return _fast_interpolate_variables( + self, s, self.__interpolation_cache) + + interpolate_variables = fast_interpolate_variables + + else: + + interpolate_variables = py_interpolate_variables + def _apply_filters(self, filters, value): for name in filters: try: @@ -1221,3 +1237,7 @@ def __repr__(self): r = "_JailedConfiguration(rootpath=%s)" % n(repr(self._path)) return r + + +if _sync_MISSING: + _sync_MISSING(_MISSING)
