# HG changeset patch # User Franz Glasner # Date 1639753609 -3600 # Node ID d7f6f2afcee2872b7f7a5bcf0ac1c351a83d14fe # Parent 5a88c514d4e05174bdfecda84d0174f2aa446a21 Instead of using u(str(v)) use specialized functions for PY2 and PY3 diff -r 5a88c514d4e0 -r d7f6f2afcee2 configmix/compat.py --- a/configmix/compat.py Fri Dec 17 15:56:53 2021 +0100 +++ b/configmix/compat.py Fri Dec 17 16:06:49 2021 +0100 @@ -16,7 +16,8 @@ "u", "u2fs", "uchr", - "n"] + "n", + "str_and_u"] import sys @@ -78,6 +79,12 @@ else: return s.encode(encoding) + def str_and_u(v): + if isinstance(v, unicode): # noqa: F821 + return v + else: + return u(str(v)) + else: def text_to_native_os_str(s, encoding=None): @@ -116,3 +123,10 @@ return s else: return s.decode(encoding) + + def str_and_u(v): + """Convert the value in `v` of any type to a native string and then + to text (Unicode) + + """ + return str(v) diff -r 5a88c514d4e0 -r d7f6f2afcee2 configmix/config.py --- a/configmix/config.py Fri Dec 17 15:56:53 2021 +0100 +++ b/configmix/config.py Fri Dec 17 16:06:49 2021 +0100 @@ -28,7 +28,7 @@ from urlparse import urlsplit from .variables import lookup_varns, lookup_filter -from .compat import u, uchr, n, PY2 +from .compat import u, uchr, n, str_and_u, PY2 from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER @@ -699,7 +699,7 @@ # None and/or empty str are handled equally here pass else: - res_append(u(str(varvalue))) + res_append(str_and_u(varvalue)) # don't re-evaluate because `self.getvar_s()` expands already rest = end + 2 start = s.find(self._STARTTOK, rest)