[web] fix Field.__str__ on py3k
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 12 Oct 2015 21:49:18 +0200
changeset 10787 34ada3b21eef
parent 10786 2ef74a6e6785
child 10788 416840faf119
[web] fix Field.__str__ on py3k
web/formfields.py
--- a/web/formfields.py	Mon Oct 12 21:48:50 2015 +0200
+++ b/web/formfields.py	Mon Oct 12 21:49:18 2015 +0200
@@ -66,7 +66,7 @@
 from warnings import warn
 from datetime import datetime, timedelta
 
-from six import text_type, string_types
+from six import PY2, text_type, string_types
 
 from logilab.mtconverter import xml_escape
 from logilab.common import nullobject
@@ -233,11 +233,14 @@
     def __unicode__(self):
         return self.as_string(False)
 
-    def __str__(self):
-        return self.as_string(False).encode('UTF8')
+    if PY2:
+        def __str__(self):
+            return self.as_string(False).encode('UTF8')
+    else:
+        __str__ = __unicode__
 
     def __repr__(self):
-        return self.as_string(True).encode('UTF8')
+        return self.as_string(True)
 
     def init_widget(self, widget):
         if widget is not None: