changeset 357:dd454e1efea4

Use constants for the names of the "None" and "Empty" filters
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 24 Jun 2021 21:20:37 +0200
parents a5c792074ec9
children 8ce46c9e70ab
files configmix/config.py configmix/constants.py configmix/variables.py
diffstat 3 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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:
--- 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"""
--- 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.