From 1b6edf7092bcb6555d93524cc19d7be0535c9dc1 Mon Sep 17 00:00:00 2001
From: Leonardo Rochael Almeida <leonardo@nexedi.com>
Date: Fri, 22 Jun 2012 12:05:30 +0200
Subject: [PATCH] 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
---
 product/Localizer/MessageCatalog.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/product/Localizer/MessageCatalog.py b/product/Localizer/MessageCatalog.py
index da3cc72027..9b4f7cd870 100644
--- a/product/Localizer/MessageCatalog.py
+++ b/product/Localizer/MessageCatalog.py
@@ -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):
-- 
2.30.9