commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r10157 - in trunk/gnue-common: . src/base src/datasources/drivers


From: reinhard
Subject: [gnue] r10157 - in trunk/gnue-common: . src/base src/datasources/drivers/other
Date: Tue, 20 Apr 2010 15:46:30 -0500 (CDT)

Author: reinhard
Date: 2010-04-20 15:46:30 -0500 (Tue, 20 Apr 2010)
New Revision: 10157

Modified:
   trunk/gnue-common/
   trunk/gnue-common/src/base/errors.py
   trunk/gnue-common/src/datasources/drivers/other/appserver.py
Log:
Avoid encoding problems when exception messages contain non-ASCII characters in
case of external (non-GNUe) exceptions.



Property changes on: trunk/gnue-common
___________________________________________________________________
Name: bzr:revision-info
   - timestamp: 2010-04-09 20:46:14.513000011 +0200
committer: Reinhard Müller <address@hidden>
properties: 
        branch-nick: common

   + timestamp: 2010-04-20 11:36:33.517999887 +0200
committer: Reinhard Müller <address@hidden>
properties: 
        branch-nick: common

Name: bzr:file-ids
   - .bzrignore bzrignore-20100409182546-xa0zbayeoj88p9k2-1
README.bzr      address@hidden:trunk%2Fgnue-common:README.svn
setup-bzr.py    address@hidden:trunk%2Fgnue-common:setup-svn.py
setup.bzr       address@hidden:trunk%2Fgnue-common:setup.svn

   + 
Name: bzr:revision-id:v3-single1-dHJ1bmsvZ251ZS1jb21tb24.
   - 3114 address@hidden

   + 3114 address@hidden
3115 address@hidden


Modified: trunk/gnue-common/src/base/errors.py
===================================================================
--- trunk/gnue-common/src/base/errors.py        2010-04-20 20:46:26 UTC (rev 
10156)
+++ trunk/gnue-common/src/base/errors.py        2010-04-20 20:46:30 UTC (rev 
10157)
@@ -104,7 +104,7 @@
         C{user}). Always an 8 bit string.
     2. C{name}: the name of the exception, usually the class name without any
         modules prepended. Always a unicode string.
-    3. C{message}: the exception message, the text priarly displayed to the
+    3. C{umessage}: the exception message, the text priarly displayed to the
         user. Always a unicode string.
     4. C{detail}: the exception detail, in many cases a string representation
         of the traceback. Always a unicode string.
@@ -165,8 +165,8 @@
     unicode strings.  All other user-defined exceptions should be derived from
     this class.
 
-    @ivar message: The error message.
-    @type message: unicode
+    @ivar umessage: The error message.
+    @type umessage: unicode
     @ivar group: The group or category of the exception. Can be one of 
'system',
         'admin', 'application', or 'user'.
     @type group: str
@@ -181,19 +181,25 @@
     """
 
     def __init__(self, message, group='system'):
+
+        # Make sure message is a unicode string.
+        if not isinstance(message, unicode):
+            message = i18n.inconv(str(message))
+
         StandardError.__init__(self, i18n.outconv(message))
-        self.message = message
-        self.group   = group
-        self.name    = None
-        self.detail  = None
 
+        self.umessage = message
+        self.group    = group
+        self.name     = None
+        self.detail   = None
 
+
     # -------------------------------------------------------------------------
     # Unicode representation
     # -------------------------------------------------------------------------
 
     def __unicode__(self):
-        return self.message
+        return self.umessage
 
 
 # =============================================================================
@@ -321,6 +327,14 @@
         else:
             name = unicode(etype.__name__)
 
+    # message
+    if isinstance(evalue, Error):
+        message = evalue.umessage
+    else:
+        # We're never sure in which encoding the message actually is, so we're
+        # cautious and use inconv which does errors='replace'.
+        message = i18n.inconv(evalue.message)
+
     # detail
     if isinstance(evalue, Error) and evalue.detail is not None:
         detail = evalue.detail
@@ -333,4 +347,4 @@
         # current encoding, so we have to convert to Unicode.
         detail = i18n.inconv(''.join(lines))
 
-    return (group, name, unicode(evalue), detail)
+    return (group, name, message, detail)

Modified: trunk/gnue-common/src/datasources/drivers/other/appserver.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/other/appserver.py        
2010-04-20 20:46:26 UTC (rev 10156)
+++ trunk/gnue-common/src/datasources/drivers/other/appserver.py        
2010-04-20 20:46:30 UTC (rev 10157)
@@ -387,7 +387,7 @@
 
     except errors.RemoteError, e:
       if e.name == 'AuthError':
-        raise Exceptions.LoginError, e.message
+        raise Exceptions.LoginError, e.umessage
       else:
         raise
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]