Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/config.py @ 705:0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
This allows using filter chains in filter-only expansions also.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 15 Aug 2023 09:34:49 +0200 |
| parents | 193a616e0b3c |
| children | 10fbc23b4dba |
line wrap: on
line diff
--- a/configmix/config.py Mon Aug 14 13:00:19 2023 +0200 +++ b/configmix/config.py Tue Aug 15 09:34:49 2023 +0200 @@ -240,6 +240,7 @@ _HIER_SEPARATOR = u(b'.') _NS_SEPARATOR = u(b':') _FILTER_SEPARATOR = u(b'|') +_FILTER_SEPARATOR_REV = u(b',') _STARTTOK_REF = _STARTTOK + REF_NAMESPACE + _NS_SEPARATOR _ENDTOK_REF = _ENDTOK _ENDTOK_FILTER = _FILTER_SEPARATOR + _ENDTOK @@ -430,20 +431,29 @@ _split_ns = _py_split_ns -def _py_split_filters(varname): +def _py_split_filters(varname, direction): """Split off the filter part from the `varname` string - :type varname: str + :param str varname: The string where to search for filters + :param int direction: +1 means to do a forward search, -1 a backward search :return: The tuple of the variable name without the filters and a list of filters :rtype: tuple(str, list) """ - name, sep, filters = varname.partition(_FILTER_SEPARATOR) + if direction == 1: + name, sep, filters = varname.partition(_FILTER_SEPARATOR) + elif direction == -1: + name, sep, filters = varname.rpartition(_FILTER_SEPARATOR) + else: + raise ValueError("`direction' must be -1 or +1") if sep: filters = filters.strip() if filters: - return (name, filters.split(_FILTER_SEPARATOR)) + if direction == 1: + return (name, filters.split(_FILTER_SEPARATOR)) + else: + return (name, filters.split(_FILTER_SEPARATOR_REV)) else: return (name, []) else: @@ -1016,7 +1026,7 @@ and (start == 0)): if s.find(_ENDTOK_FILTER, 3) != (len_s - 3): raise ValueError("`{{|' global filter interpolation must end with `|}}'") - new_s, filters = _split_filters(s[3:-3]) + new_s, filters = _split_filters(s[3:-3], -1) try: varvalue = self.py_interpolate_variables(new_s) except KeyError: @@ -1039,7 +1049,7 @@ rest = start break varname, filters = _split_filters( - s[start+2:end]) # noqa: E226 + s[start+2:end], 1) # noqa: E226 try: varvalue, cacheable = self._py_getvar_s_with_cache_info(varname) except KeyError:
