Localizer: fix to_unicode() default_encoding and non-str

Don't fix the default_encoding at import time as it can be overriden later (ex. by a later import of zope configuration).

Don't assume objects to be str if they're not unicode
parent 30522c8d
......@@ -63,13 +63,13 @@ def md5text(str):
return md5(str.encode('utf-8')).hexdigest()
def to_unicode(x, encoding=HTTPRequest.default_encoding):
def to_unicode(x, encoding=None):
"""In Zope the ISO-8859-1 encoding has an special status, normal strings
are considered to be in this encoding by default.
"""
if isinstance(x, unicode):
return x
return unicode(x, encoding)
if isinstance(x, str):
unicode(x, encoding or HTTPRequest.default_encoding)
return unicode(x)
def to_str(x):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment