Mercurial > hgrepos > Python > libs > ConfigMix
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 704:457ef358c1a0 | 705:0485a033c95d |
|---|---|
| 238 _STARTTOK = u(b"{{") | 238 _STARTTOK = u(b"{{") |
| 239 _ENDTOK = u(b"}}") | 239 _ENDTOK = u(b"}}") |
| 240 _HIER_SEPARATOR = u(b'.') | 240 _HIER_SEPARATOR = u(b'.') |
| 241 _NS_SEPARATOR = u(b':') | 241 _NS_SEPARATOR = u(b':') |
| 242 _FILTER_SEPARATOR = u(b'|') | 242 _FILTER_SEPARATOR = u(b'|') |
| 243 _FILTER_SEPARATOR_REV = u(b',') | |
| 243 _STARTTOK_REF = _STARTTOK + REF_NAMESPACE + _NS_SEPARATOR | 244 _STARTTOK_REF = _STARTTOK + REF_NAMESPACE + _NS_SEPARATOR |
| 244 _ENDTOK_REF = _ENDTOK | 245 _ENDTOK_REF = _ENDTOK |
| 245 _ENDTOK_FILTER = _FILTER_SEPARATOR + _ENDTOK | 246 _ENDTOK_FILTER = _FILTER_SEPARATOR + _ENDTOK |
| 246 _DOT = u(b'.') | 247 _DOT = u(b'.') |
| 247 _TILDE = u(b'~') | 248 _TILDE = u(b'~') |
| 428 _split_ns = _fast_split_ns | 429 _split_ns = _fast_split_ns |
| 429 else: | 430 else: |
| 430 _split_ns = _py_split_ns | 431 _split_ns = _py_split_ns |
| 431 | 432 |
| 432 | 433 |
| 433 def _py_split_filters(varname): | 434 def _py_split_filters(varname, direction): |
| 434 """Split off the filter part from the `varname` string | 435 """Split off the filter part from the `varname` string |
| 435 | 436 |
| 436 :type varname: str | 437 :param str varname: The string where to search for filters |
| 438 :param int direction: +1 means to do a forward search, -1 a backward search | |
| 437 :return: The tuple of the variable name without the filters and a list | 439 :return: The tuple of the variable name without the filters and a list |
| 438 of filters | 440 of filters |
| 439 :rtype: tuple(str, list) | 441 :rtype: tuple(str, list) |
| 440 | 442 |
| 441 """ | 443 """ |
| 442 name, sep, filters = varname.partition(_FILTER_SEPARATOR) | 444 if direction == 1: |
| 445 name, sep, filters = varname.partition(_FILTER_SEPARATOR) | |
| 446 elif direction == -1: | |
| 447 name, sep, filters = varname.rpartition(_FILTER_SEPARATOR) | |
| 448 else: | |
| 449 raise ValueError("`direction' must be -1 or +1") | |
| 443 if sep: | 450 if sep: |
| 444 filters = filters.strip() | 451 filters = filters.strip() |
| 445 if filters: | 452 if filters: |
| 446 return (name, filters.split(_FILTER_SEPARATOR)) | 453 if direction == 1: |
| 454 return (name, filters.split(_FILTER_SEPARATOR)) | |
| 455 else: | |
| 456 return (name, filters.split(_FILTER_SEPARATOR_REV)) | |
| 447 else: | 457 else: |
| 448 return (name, []) | 458 return (name, []) |
| 449 else: | 459 else: |
| 450 return (name, []) | 460 return (name, []) |
| 451 | 461 |
| 1014 if ((len_s >= 6) | 1024 if ((len_s >= 6) |
| 1015 and (s[2] == _FILTER_SEPARATOR) | 1025 and (s[2] == _FILTER_SEPARATOR) |
| 1016 and (start == 0)): | 1026 and (start == 0)): |
| 1017 if s.find(_ENDTOK_FILTER, 3) != (len_s - 3): | 1027 if s.find(_ENDTOK_FILTER, 3) != (len_s - 3): |
| 1018 raise ValueError("`{{|' global filter interpolation must end with `|}}'") | 1028 raise ValueError("`{{|' global filter interpolation must end with `|}}'") |
| 1019 new_s, filters = _split_filters(s[3:-3]) | 1029 new_s, filters = _split_filters(s[3:-3], -1) |
| 1020 try: | 1030 try: |
| 1021 varvalue = self.py_interpolate_variables(new_s) | 1031 varvalue = self.py_interpolate_variables(new_s) |
| 1022 except KeyError: | 1032 except KeyError: |
| 1023 if NONE_FILTER in filters: | 1033 if NONE_FILTER in filters: |
| 1024 varvalue = None | 1034 varvalue = None |
| 1037 end = s.find(_ENDTOK, start) | 1047 end = s.find(_ENDTOK, start) |
| 1038 if end < 0: | 1048 if end < 0: |
| 1039 rest = start | 1049 rest = start |
| 1040 break | 1050 break |
| 1041 varname, filters = _split_filters( | 1051 varname, filters = _split_filters( |
| 1042 s[start+2:end]) # noqa: E226 | 1052 s[start+2:end], 1) # noqa: E226 |
| 1043 try: | 1053 try: |
| 1044 varvalue, cacheable = self._py_getvar_s_with_cache_info(varname) | 1054 varvalue, cacheable = self._py_getvar_s_with_cache_info(varname) |
| 1045 except KeyError: | 1055 except KeyError: |
| 1046 cacheable = True | 1056 cacheable = True |
| 1047 if NONE_FILTER in filters: | 1057 if NONE_FILTER in filters: |
