[Checkins] SVN: zope.publisher/trunk/ Add handy DoNotReRaiseException adapter that can be simply registered for exceptions to mark that they should not be re-raised.

Dan Korostelev nadako at gmail.com
Wed Sep 9 05:58:19 EDT 2009


Log message for revision 103682:
  Add handy DoNotReRaiseException adapter that can be simply registered for exceptions to mark that they should not be re-raised.
  Add __call__ method to the IReRaiseException interface.

Changed:
  U   zope.publisher/trunk/CHANGES.txt
  U   zope.publisher/trunk/src/zope/publisher/interfaces/__init__.py
  U   zope.publisher/trunk/src/zope/publisher/publish.py
  U   zope.publisher/trunk/src/zope/publisher/tests/test_publisher.py

-=-
Modified: zope.publisher/trunk/CHANGES.txt
===================================================================
--- zope.publisher/trunk/CHANGES.txt	2009-09-09 09:44:02 UTC (rev 103681)
+++ zope.publisher/trunk/CHANGES.txt	2009-09-09 09:58:19 UTC (rev 103682)
@@ -6,6 +6,11 @@
 
 - Make redirect validation works without HTTP_HOST variable.
 
+- Add DoNotReRaiseException adapter that can be registered
+  for exceptions to flag that they should not be re-raised by
+  publisher when ``handle_errors`` parameter of the ``publish``
+  method is False.
+
 3.9.1 (2009-09-01)
 ------------------
 

Modified: zope.publisher/trunk/src/zope/publisher/interfaces/__init__.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/interfaces/__init__.py	2009-09-09 09:44:02 UTC (rev 103681)
+++ zope.publisher/trunk/src/zope/publisher/interfaces/__init__.py	2009-09-09 09:58:19 UTC (rev 103682)
@@ -515,3 +515,6 @@
     basic-auth when a debugger middleware is used and `IUnauthorized`
     is raised.
     """
+
+    def __call__(self):
+        """Return if an exception should be re-raised"""

Modified: zope.publisher/trunk/src/zope/publisher/publish.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/publish.py	2009-09-09 09:44:02 UTC (rev 103681)
+++ zope.publisher/trunk/src/zope/publisher/publish.py	2009-09-09 09:58:19 UTC (rev 103682)
@@ -19,6 +19,7 @@
 """
 import sys
 from zope import component
+from zope.interface import implements
 from zope.publisher.interfaces import Retry, IReRaiseException
 from zope.proxy import removeAllProxies
 
@@ -192,3 +193,15 @@
     # Return the request, since it might be a different object than the one
     # that was passed in.
     return request
+
+
+class DoNotReRaiseException(object):
+    """Marker adapter for exceptions that should not be re-raised"""
+    
+    implements(IReRaiseException)
+    
+    def __init__(self, exc):
+        pass
+
+    def __call__(self):
+        return False

Modified: zope.publisher/trunk/src/zope/publisher/tests/test_publisher.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/tests/test_publisher.py	2009-09-09 09:44:02 UTC (rev 103681)
+++ zope.publisher/trunk/src/zope/publisher/tests/test_publisher.py	2009-09-09 09:58:19 UTC (rev 103682)
@@ -18,7 +18,7 @@
 import unittest
 
 from zope import component
-from zope.publisher.publish import publish
+from zope.publisher.publish import publish, DoNotReRaiseException
 from zope.publisher.base import TestRequest
 from zope.publisher.base import DefaultPublication
 from zope.publisher.interfaces import Unauthorized, NotFound, DebugError
@@ -105,19 +105,14 @@
 
     def testIReRaiseExceptionAdapters(self):
 
-        def dontReRaiseAdapter(context):
-            def shouldBeReRaised():
-                return False
-            return shouldBeReRaised
-
-        self._registerExcAdapter(dontReRaiseAdapter)
+        self._registerExcAdapter(DoNotReRaiseException)
         try:
             self._publisherResults('/_item')
         except Unauthorized:
-            self._unregisterExcAdapter(dontReRaiseAdapter)
+            self._unregisterExcAdapter(DoNotReRaiseException)
             self.fail('Unauthorized raised though this should '
                             'not happen')
-        self._unregisterExcAdapter(dontReRaiseAdapter)
+        self._unregisterExcAdapter(DoNotReRaiseException)
 
         def doReRaiseAdapter(context):
             def shouldBeReRaised():



More information about the checkins mailing list