[Checkins] SVN: Zope/branches/2.12/ - fixed handling of exceptions with unicode values

Yvo Schubbe y.2010 at wcm-solutions.de
Wed Apr 21 05:00:15 EDT 2010


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

Changed:
  U   Zope/branches/2.12/doc/CHANGES.rst
  UU  Zope/branches/2.12/src/ZPublisher/HTTPResponse.py
  U   Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt

-=-
Modified: Zope/branches/2.12/doc/CHANGES.rst
===================================================================
--- Zope/branches/2.12/doc/CHANGES.rst	2010-04-21 08:08:50 UTC (rev 111198)
+++ Zope/branches/2.12/doc/CHANGES.rst	2010-04-21 09:00:13 UTC (rev 111199)
@@ -55,6 +55,8 @@
 Bugs Fixed
 ++++++++++
 
+- HTTPResponse: Fixed handling of exceptions with unicode values.
+
 - zExceptions: Fixed some unicode issues in Unauthorized.
 
 - LP #372632, comments #15ff.: Fixed regression in Unauthorized handling.

Modified: Zope/branches/2.12/src/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/branches/2.12/src/ZPublisher/HTTPResponse.py	2010-04-21 08:08:50 UTC (rev 111198)
+++ Zope/branches/2.12/src/ZPublisher/HTTPResponse.py	2010-04-21 09:00:13 UTC (rev 111199)
@@ -800,7 +800,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__
 


Property changes on: Zope/branches/2.12/src/ZPublisher/HTTPResponse.py
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
   - 1.81

Modified: Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt
===================================================================
--- Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt	2010-04-21 08:08:50 UTC (rev 111198)
+++ Zope/branches/2.12/src/ZPublisher/tests/exception_handling.txt	2010-04-21 09:00:13 UTC (rev 111199)
@@ -140,6 +140,28 @@
     ...
     Unauthorized: ERROR VALUE
 
+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>
+
 Handle zExceptions.Unauthorized raised by BaseRequest.traverse. We take the
 'WWW-Authenticate' header as a sign that HTTPResponse._unauthorized was called.
 



More information about the checkins mailing list