# HG changeset patch # User Franz Glasner # Date 1692090891 -7200 # Node ID e692216f875608e1fc34ec9aa1115a2a3bf9a8dc # Parent 10fbc23b4dba085535005e01f0f6628708006cf1 Allow also "," characters to act as a separator within a filter-chain. The first filter is introduced by a "|", optional other ones may be introduced by a "|" or a ",". diff -r 10fbc23b4dba -r e692216f8756 configmix/_speedups.c --- a/configmix/_speedups.c Tue Aug 15 10:41:22 2023 +0200 +++ b/configmix/_speedups.c Tue Aug 15 11:14:51 2023 +0200 @@ -684,7 +684,12 @@ } if (direction == 1) { - tmp = PyUnicode_Split(filters, sstate->FILTER_SEPARATOR, -1); + if (PySequence_Contains(filters, sstate->FILTER_SEPARATOR_2)) { + tmp = PyUnicode_Split(filters, sstate->FILTER_SEPARATOR_2, -1); + } + else { + tmp = PyUnicode_Split(filters, sstate->FILTER_SEPARATOR, -1); + } } else { tmp = PyUnicode_Split(filters, sstate->FILTER_SEPARATOR_2, -1); diff -r 10fbc23b4dba -r e692216f8756 configmix/config.py --- a/configmix/config.py Tue Aug 15 10:41:22 2023 +0200 +++ b/configmix/config.py Tue Aug 15 11:14:51 2023 +0200 @@ -451,7 +451,10 @@ filters = filters.strip() if filters: if direction == 1: - return (name, filters.split(_FILTER_SEPARATOR)) + if _FILTER_SEPARATOR_2 in filters: + return (name, filters.split(_FILTER_SEPARATOR_2)) + else: + return (name, filters.split(_FILTER_SEPARATOR)) else: return (name, filters.split(_FILTER_SEPARATOR_2)) else: diff -r 10fbc23b4dba -r e692216f8756 docs/introduction.rst --- a/docs/introduction.rst Tue Aug 15 10:41:22 2023 +0200 +++ b/docs/introduction.rst Tue Aug 15 11:14:51 2023 +0200 @@ -460,9 +460,14 @@ {{[namespace:]variable[|filter[|filter...]]}} +or:: + + {{[namespace:]variable[|filter[,filter...]]}} + I.e.: between double curly braces an optional `namespace` name followed by -a colon ``:``, the `variable` and then zero or more filters, each one -introduced by a pipe symbol ``|``. +a colon ``:``, the `variable` and then zero or more filters, the first one +introduced by a pipe symbol ``|`` the following ones introduced by a +comma ``,`` or a pipe symbol ``|``. The comma ``,`` should be preferred. Variables are expanded *lately* at runtime -- exactly when calling :py:meth:`.Configuration.getvar_s`, @@ -474,13 +479,20 @@ *must* be quoted (see :ref:`quoting`) when using variable interpolation syntax. +.. note:: Commata ``,`` and pipe symbols ``|`` are not allowed within + filter names. + Filter functions ~~~~~~~~~~~~~~~~ Interpolated values can be processed through a series of filter functions:: - {{my.variable|filter1|filter2}} + {{my.variable|filter1|filter2|filter3}} + +or:: + + {{my.variable|filter1,filter2,filter3}} Available filter functions are: diff -r 10fbc23b4dba -r e692216f8756 tests/test.py --- a/tests/test.py Tue Aug 15 10:41:22 2023 +0200 +++ b/tests/test.py Tue Aug 15 11:14:51 2023 +0200 @@ -2229,6 +2229,10 @@ self.assertEqual((u"the-varname", [u"Empty", u"None"]), self.split_filters(u"the-varname|Empty|None", 1)) + def test_split_filters_many_alt(self): + self.assertEqual((u"the-varname", [u"Empty", u"None"]), + self.split_filters(u"the-varname|Empty,None", 1)) + def test_None_filter_single(self): cfg = configmix.load() x = getattr(cfg, self.interpolate_meth)(u"{{non-existing|None}}")