[Checkins] SVN: Zope/trunk/ - RESPONSE.handle_errors was wrongly set (to debug, should have been

Sidnei da Silva sidnei.da.silva at gmail.com
Thu May 7 19:18:40 EDT 2009


Log message for revision 99805:
  - RESPONSE.handle_errors was wrongly set (to debug, should have been
    ``not debug``). Also, the check for exception constructor arguments
    didn't account for exceptions that didn't override the ``__init__``
    (which are most of them). The combination of those two problems
    caused the ``standard_error_message`` not to be called. Fixes
    https://bugs.edge.launchpad.net/zope2/+bug/372632 .
  
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/OFS/SimpleItem.py
  U   Zope/trunk/src/OFS/tests/testSimpleItem.py
  U   Zope/trunk/src/ZPublisher/Publish.py
  U   Zope/trunk/src/ZPublisher/Test.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst	2009-05-07 19:07:21 UTC (rev 99804)
+++ Zope/trunk/doc/CHANGES.rst	2009-05-07 23:18:39 UTC (rev 99805)
@@ -36,6 +36,13 @@
 Bugs Fixed
 ++++++++++
 
+- RESPONSE.handle_errors was wrongly set (to debug, should have been
+  ``not debug``). Also, the check for exception constructor arguments
+  didn't account for exceptions that didn't override the ``__init__``
+  (which are most of them). The combination of those two problems
+  caused the ``standard_error_message`` not to be called. Fixes
+  https://bugs.edge.launchpad.net/zope2/+bug/372632 .
+
 - DocumentTemplate.DT_Raise:  use new 'zExceptions.convertExceptionType'
   API to allow raising non-builtin exceptions.
   Fixes https://bugs.launchpad.net/zope2/+bug/372629 , which prevented
@@ -50,7 +57,7 @@
 Bugs Fixed
 ++++++++++
 
-- fixed versions.cfg in order to support zope.z2release for 
+- fixed versions.cfg in order to support zope.z2release for
   creating a proper index structure
 
 2.12.0a3 (2009-04-19)

Modified: Zope/trunk/src/OFS/SimpleItem.py
===================================================================
--- Zope/trunk/src/OFS/SimpleItem.py	2009-05-07 19:07:21 UTC (rev 99804)
+++ Zope/trunk/src/OFS/SimpleItem.py	2009-05-07 23:18:39 UTC (rev 99805)
@@ -237,15 +237,24 @@
             if not REQUEST:
                 REQUEST = aq_acquire(self, 'REQUEST')
 
-            handle_errors = getattr(getattr(REQUEST, 'RESPONSE', None), 
+            handle_errors = getattr(getattr(REQUEST, 'RESPONSE', None),
                                     'handle_errors', False)
             # Can we re-raise the exception with a rendered-to-HTML
             # exception value? To be able to do so, the exception
             # constructor needs to be able to take more than two
             # arguments (some Zope 3 exceptions can't).
-            ctor = getattr(getattr(error_type, '__init__', None), 'im_func', None)
-            can_raise = (ctor is not None and inspect.isfunction(ctor) 
-                         and len(inspect.getargspec(error_type.__init__)[0]) > 2)
+            ctor = getattr(error_type, '__init__', None)
+            if inspect.ismethoddescriptor(ctor):
+                # If it's a method descriptor, it means we've got a
+                # base ``__init__`` method that was not overriden,
+                # likely from the base ``Exception`` class.
+                can_raise = True
+            else:
+                if inspect.ismethod(ctor):
+                    ctor = getattr(ctor, 'im_func', None)
+                can_raise = (
+                    ctor is not None and inspect.isfunction(ctor)
+                    and len(inspect.getargspec(error_type.__init__)[0]) > 2)
 
             if not (can_raise and handle_errors):
                 # If we have been asked not to handle errors and we

Modified: Zope/trunk/src/OFS/tests/testSimpleItem.py
===================================================================
--- Zope/trunk/src/OFS/tests/testSimpleItem.py	2009-05-07 19:07:21 UTC (rev 99804)
+++ Zope/trunk/src/OFS/tests/testSimpleItem.py	2009-05-07 23:18:39 UTC (rev 99805)
@@ -32,7 +32,36 @@
 
         verifyClass(ISimpleItem, SimpleItem)
 
+    def test_standard_error_message_is_called(self):
+        from zExceptions import BadRequest
+        from OFS.SimpleItem import SimpleItem
 
+        # handle_errors should default to True. It is a flag used for
+        # functional doctests. See ZPublisher/Test.py and
+        # ZPublisher/Publish.py.
+        class REQUEST(object):
+            class RESPONSE(object):
+                handle_errors = True
+
+        class StandardErrorMessage(object):
+            def __init__(self):
+                self.kw = {}
+
+            def __call__(self, **kw):
+                self.kw.clear()
+                self.kw.update(kw)
+
+        item = SimpleItem()
+        item.standard_error_message = sem = StandardErrorMessage()
+
+        try:
+            raise BadRequest("1")
+        except:
+            item.raise_standardErrorMessage(client=item,
+                                            REQUEST=REQUEST())
+
+        self.assertEquals(sem.kw.get('error_type'), 'BadRequest')
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestItem),

Modified: Zope/trunk/src/ZPublisher/Publish.py
===================================================================
--- Zope/trunk/src/ZPublisher/Publish.py	2009-05-07 19:07:21 UTC (rev 99804)
+++ Zope/trunk/src/ZPublisher/Publish.py	2009-05-07 23:18:39 UTC (rev 99805)
@@ -194,7 +194,7 @@
             else:
                 stdout=response.stdout
 
-            response.handle_errors = debug
+            response.handle_errors = not debug
 
             if request is None:
                 request=Request(stdin, environ, response)

Modified: Zope/trunk/src/ZPublisher/Test.py
===================================================================
--- Zope/trunk/src/ZPublisher/Test.py	2009-05-07 19:07:21 UTC (rev 99804)
+++ Zope/trunk/src/ZPublisher/Test.py	2009-05-07 23:18:39 UTC (rev 99805)
@@ -188,7 +188,7 @@
             else:
                 stdout=response.stdout
 
-            response.handle_errors = debug
+            response.handle_errors = not debug
 
             if request is None:
                 request=Request(stdin, environ, response)



More information about the Checkins mailing list