[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/error/ Fix for http://www.zope.org/Collectors/Zope3-dev/410

Gintautas Miliauskas gintas at pov.lt
Fri May 20 04:26:56 EDT 2005


Log message for revision 30458:
  Fix for http://www.zope.org/Collectors/Zope3-dev/410
  (ErrorReportingUtility can't handle unicode in principal information).
  

Changed:
  U   Zope3/trunk/src/zope/app/error/error.py
  U   Zope3/trunk/src/zope/app/error/tests.py

-=-
Modified: Zope3/trunk/src/zope/app/error/error.py
===================================================================
--- Zope3/trunk/src/zope/app/error/error.py	2005-05-20 08:25:43 UTC (rev 30457)
+++ Zope3/trunk/src/zope/app/error/error.py	2005-05-20 08:26:55 UTC (rev 30458)
@@ -107,7 +107,7 @@
                         login = request.principal.getLogin()
                     else:
                         login = 'unauthenticated'
-                    username = ', '.join(map(str, (login,
+                    username = ', '.join(map(unicode, (login,
                                           request.principal.id,
                                           request.principal.title,
                                           request.principal.description

Modified: Zope3/trunk/src/zope/app/error/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/error/tests.py	2005-05-20 08:25:43 UTC (rev 30457)
+++ Zope3/trunk/src/zope/app/error/tests.py	2005-05-20 08:26:55 UTC (rev 30458)
@@ -66,16 +66,22 @@
 
         tb_text = ''.join(format_exception(*exc_info, **{'as_html': 0}))
 
-        err_id =  getErrLog[0]['id']
+        err_id = getErrLog[0]['id']
         self.assertEquals(tb_text,
                           errUtility.getLogEntryById(err_id)['tb_text'])
 
-    def test_ErrorLog_Unicode_urls(self):
+    def test_ErrorLog_unicode(self):
         # Emulate a unicode url, it gets encoded to utf-8 before it's passed
         # to the request. Also add some unicode field to the request's
-        # environment
+        # environment and make the principal's title unicode.
         request = TestRequest(environ={'PATH_INFO': '/\xd1\x82',
                                        'SOME_UNICODE': u'\u0441'})
+        class PrincipalStub(object):
+            id = u'\u0441'
+            title = u'\u0441'
+            description = u'\u0441'
+        request.setPrincipal(PrincipalStub())
+
         errUtility = ErrorReportingUtility()
         exc_info = C1().getAnErrorInfo()
         errUtility.raising(exc_info, request=request)
@@ -84,11 +90,14 @@
 
         tb_text = ''.join(format_exception(*exc_info, **{'as_html': 0}))
 
-        err_id =  getErrLog[0]['id']
+        err_id = getErrLog[0]['id']
         self.assertEquals(tb_text,
                           errUtility.getLogEntryById(err_id)['tb_text'])
-        
 
+        username = getErrLog[0]['username']
+        self.assertEquals(username, u'unauthenticated, \u0441, \u0441, \u0441')
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(ErrorReportingUtilityTests),



More information about the Zope3-Checkins mailing list