# HG changeset patch # User RĂ©mi Cardona # Date 1442484160 -7200 # Node ID 3cb87b61b067d326057dd790a6c22be1d6dd4e3b # Parent f94c812c36696c0e8d010a1d08046f5bc25e4c3d [py3k] __unicode__ and __str__ diff -r f94c812c3669 -r 3cb87b61b067 _exceptions.py --- a/_exceptions.py Thu Sep 17 11:07:36 2015 +0200 +++ b/_exceptions.py Thu Sep 17 12:02:40 2015 +0200 @@ -21,6 +21,8 @@ from warnings import warn +from six import PY3, text_type + from logilab.common.decorators import cachedproperty from yams import ValidationError @@ -30,14 +32,15 @@ class CubicWebException(Exception): """base class for cubicweb server exception""" msg = "" - def __str__(self): + def __unicode__(self): if self.msg: if self.args: return self.msg % tuple(self.args) else: return self.msg else: - return u' '.join(unicode(arg) for arg in self.args) + return u' '.join(text_type(arg) for arg in self.args) + __str__ = __unicode__ if PY3 else lambda self: self.__unicode__().encode('utf-8') class ConfigurationError(CubicWebException): """a misconfiguration error""" diff -r f94c812c3669 -r 3cb87b61b067 uilib.py --- a/uilib.py Thu Sep 17 11:07:36 2015 +0200 +++ b/uilib.py Thu Sep 17 12:02:40 2015 +0200 @@ -340,8 +340,7 @@ if self.parent: return u'%s.%s' % (self.parent, self.id) return text_type(self.id) - def __str__(self): - return text_type(self).encode('utf8') + __str__ = __unicode__ if PY3 else lambda self: self.__unicode__().encode('utf-8') def __getattr__(self, attr): return _JSId(attr, self) def __call__(self, *args): @@ -359,6 +358,7 @@ if self.parent: return u'%s(%s)' % (self.parent, ','.join(args)) return ','.join(args) + __str__ = __unicode__ if PY3 else lambda self: self.__unicode__().encode('utf-8') class _JS(object): def __getattr__(self, attr):