From 440df681bfd9fab39dffad3fa708725f34d5109d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ha=CC=88cker?= Date: Fri, 5 May 2017 15:51:56 +0200 Subject: [PATCH] Fix field2string to always convert to the native string format (and remove the `unicode = str` workaround that is just wrong). This means some other tests might fail now that worked before, but those need better fixes anyway. --- src/ZPublisher/Converters.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ZPublisher/Converters.py b/src/ZPublisher/Converters.py index a94baf16f2..69244cd2ed 100644 --- a/src/ZPublisher/Converters.py +++ b/src/ZPublisher/Converters.py @@ -16,18 +16,18 @@ from DateTime import DateTime from DateTime.interfaces import SyntaxError from cgi import escape - -if sys.version_info >= (3, ): - unicode = str +import six # This may get overwritten during configuration default_encoding = 'utf-8' def field2string(v): + """Converts value to native strings (so always to `str` no matter which + python version you are on)""" if hasattr(v, 'read'): return v.read() - elif isinstance(v, unicode): + elif six.PY2 and isinstance(v, six.text_type): return v.encode(default_encoding) else: return str(v)