Log message for revision 111200:
  - fixed handling of exceptions with unicode values

Changed:
  U   Zope/trunk/src/ZPublisher/HTTPResponse.py
  U   Zope/trunk/src/ZPublisher/tests/exception_handling.txt

-=-
Modified: Zope/trunk/src/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/trunk/src/ZPublisher/HTTPResponse.py   2010-04-21 09:00:13 UTC (rev 
111199)
+++ Zope/trunk/src/ZPublisher/HTTPResponse.py   2010-04-21 09:01:04 UTC (rev 
111200)
@@ -795,7 +795,10 @@
         b = v
         if isinstance(b, Exception):
             try:
-                b = str(b)
+                try:
+                    b = str(b)
+                except UnicodeEncodeError:
+                    b = self._encode_unicode(unicode(b))
             except:
                 b = '<unprintable %s object>' % type(b).__name__
 

Modified: Zope/trunk/src/ZPublisher/tests/exception_handling.txt
===================================================================
--- Zope/trunk/src/ZPublisher/tests/exception_handling.txt      2010-04-21 
09:00:13 UTC (rev 111199)
+++ Zope/trunk/src/ZPublisher/tests/exception_handling.txt      2010-04-21 
09:01:04 UTC (rev 111200)
@@ -147,6 +147,29 @@
     Unauthorized: ERROR VALUE
     >>> browser.contents
 
+And the same with unicode error value.
+
+    >>> app.test_folder_1_.foo.exception = Unauthorized(u'ERROR VALUE \u03A9')
+
+    >>> browser.handleErrors = True
+    >>> browser.open('http://localhost/test_folder_1_/foo')
+    Traceback (most recent call last):
+    ...
+    HTTPError: HTTP Error 401: Unauthorized
+    >>> 'Error Type: Unauthorized' in browser.contents
+    True
+    >>> 'Error Value: ERROR VALUE ?' in browser.contents
+    True
+    >>> browser.headers['WWW-Authenticate']
+    'basic realm="Zope2"'
+
+    >>> browser.handleErrors = False
+    >>> browser.open('http://localhost/test_folder_1_/foo')
+    Traceback (most recent call last):
+    ...
+    Unauthorized: <unprintable ... object>
+    >>> browser.contents
+
 Handle zExceptions.Unauthorized raised by BaseRequest.traverse. We take the
 'WWW-Authenticate' header as a sign that HTTPResponse._unauthorized was called.
 

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to