[exceptions] fix string conversion for Unauthorized exception
authorArthur Lutz <arthur.lutz@logilab.fr>
Wed, 10 Feb 2016 14:43:05 +0100
changeset 11103 d1798710f922
parent 11102 cd1267c1243e
child 11104 269317987dc6
[exceptions] fix string conversion for Unauthorized exception changeset 3cb87b61b067 changed CubicWebException to define __unicode__ as the main entry point for string conversion, but left Unauthorized's __str__ definition unchanged, leading to a mismatch. Closes #10646396.
_exceptions.py
--- a/_exceptions.py	Mon Feb 08 11:01:46 2016 +0100
+++ b/_exceptions.py	Wed Feb 10 14:43:05 2016 +0100
@@ -117,19 +117,19 @@
     """raised when a user tries to perform an action without sufficient
     credentials
     """
-    msg = 'You are not allowed to perform this operation'
-    msg1 = 'You are not allowed to perform %s operation on %s'
+    msg = u'You are not allowed to perform this operation'
+    msg1 = u'You are not allowed to perform %s operation on %s'
     var = None
 
-    def __str__(self):
+    def __unicode__(self):
         try:
             if self.args and len(self.args) == 2:
                 return self.msg1 % self.args
             if self.args:
-                return ' '.join(self.args)
+                return u' '.join(self.args)
             return self.msg
         except Exception as ex:
-            return str(ex)
+            return text_type(ex)
 
 class Forbidden(SecurityError):
     """raised when a user tries to perform a forbidden action