# HG changeset patch # User Franz Glasner # Date 1624562437 -7200 # Node ID dd454e1efea4238a8d5d6a874c703dd00aae5109 # Parent a5c792074ec959693b2d3e3a4c231f0f45ffb180 Use constants for the names of the "None" and "Empty" filters diff -r a5c792074ec9 -r dd454e1efea4 configmix/config.py --- a/configmix/config.py Thu Jun 24 20:52:21 2021 +0200 +++ b/configmix/config.py Thu Jun 24 21:20:37 2021 +0200 @@ -29,7 +29,7 @@ from .variables import lookup_varns, lookup_filter from .compat import u, uchr -from .constants import REF_NAMESPACE +from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER _MARKER = object() @@ -345,10 +345,10 @@ return s varname, filters = self._split_filters(s[start+2:end]) try: - if "None" in filters: + if NONE_FILTER in filters: varvalue = self._apply_filters( filters, self.getvar_s(varname, default=None)) - elif "Empty" in filters: + elif EMPTY_FILTER in filters: varvalue = self._apply_filters( filters, self.getvar_s(varname, default=u(""))) else: diff -r a5c792074ec9 -r dd454e1efea4 configmix/constants.py --- a/configmix/constants.py Thu Jun 24 20:52:21 2021 +0200 +++ b/configmix/constants.py Thu Jun 24 21:20:37 2021 +0200 @@ -36,3 +36,9 @@ `references` """ + +NONE_FILTER = u("None") +"""The public name of the special `None` filter""" + +EMPTY_FILTER = u("Empty") +"""The public name of the special `None` filter""" diff -r a5c792074ec9 -r dd454e1efea4 configmix/variables.py --- a/configmix/variables.py Thu Jun 24 20:52:21 2021 +0200 +++ b/configmix/variables.py Thu Jun 24 21:20:37 2021 +0200 @@ -17,8 +17,8 @@ import platform from functools import wraps -from .compat import PY2, native_os_str_to_text, u -from .constants import REF_NAMESPACE +from .compat import PY2, native_os_str_to_text, text_to_native_os_str, u +from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER _MARKER = object() @@ -244,7 +244,7 @@ return v.upper() -@filter("None") +@filter(text_to_native_os_str(NONE_FILTER, encoding="ascii")) def None_filter_impl(config, v): """Identity. @@ -255,7 +255,7 @@ return v -@filter("Empty") +@filter(text_to_native_os_str(EMPTY_FILTER, encoding="ascii")) def Empty_filter_impl(config, v): """Identity.