From 375629dfd3de4fb39841bd62a5170aace1d47cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 26 Sep 2017 01:33:02 +0200 Subject: [PATCH] Support unicode in message and description of TrytonException The easiest way to support both Python 2 and 3 is to implement __unicode__ and encode the result for __str__. issue6768 review39681002 --- trytond/exceptions.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/trytond/exceptions.py b/trytond/exceptions.py index 68922344e8..a42b20fdda 100644 --- a/trytond/exceptions.py +++ b/trytond/exceptions.py @@ -3,7 +3,9 @@ class TrytonException(Exception): - pass + + def __str__(self): + return unicode(self).encode('utf-8') class UserError(TrytonException): @@ -14,8 +16,8 @@ class UserError(TrytonException): self.description = description self.code = 1 - def __str__(self): - return '%s - %s' % (self.message, self.description) + def __unicode__(self): + return u'%s - %s' % (self.message, self.description) class UserWarning(TrytonException): @@ -28,8 +30,8 @@ class UserWarning(TrytonException): self.description = description self.code = 2 - def __str__(self): - return '%s - %s' % (self.message, self.description) + def __unicode__(self): + return u'%s - %s' % (self.message, self.description) class LoginException(TrytonException): @@ -54,7 +56,7 @@ class ConcurrencyException(TrytonException): self.message = message self.code = 4 - def __str__(self): + def __unicode__(self): return self.message @@ -67,5 +69,5 @@ class MissingDependenciesException(TrytonException): def __init__(self, missings): self.missings = missings - def __str__(self): + def __unicode__(self): return 'Missing dependencies: %s' % ' '.join(self.missings)