Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/config.py @ 703:193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 14 Aug 2023 09:31:27 +0200 |
| parents | 58dc57bed012 |
| children | 0485a033c95d |
line wrap: on
line diff
--- a/configmix/config.py Sun Aug 13 16:14:39 2023 +0200 +++ b/configmix/config.py Mon Aug 14 09:31:27 2023 +0200 @@ -242,6 +242,7 @@ _FILTER_SEPARATOR = u(b'|') _STARTTOK_REF = _STARTTOK + REF_NAMESPACE + _NS_SEPARATOR _ENDTOK_REF = _ENDTOK +_ENDTOK_FILTER = _FILTER_SEPARATOR + _ENDTOK _DOT = u(b'.') _TILDE = u(b'~') _QUOTE = u(b'%') @@ -1009,6 +1010,24 @@ "%r (cached)" % (s, )) else: return res + + if ((len_s >= 6) + and (s[2] == _FILTER_SEPARATOR) + 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]) + try: + varvalue = self.py_interpolate_variables(new_s) + except KeyError: + if NONE_FILTER in filters: + varvalue = None + elif EMPTY_FILTER in filters: + varvalue = _EMPTY_STR + else: + raise + varvalue = self._apply_filters(filters, varvalue) + return varvalue res = [] res_append = res.append rest = 0
