[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - BaseRequest.py:1.55

Christian Theune ct at gocept.com
Wed Mar 3 06:07:42 EST 2004


Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv14472/lib/python/ZPublisher

Modified Files:
	BaseRequest.py 
Log Message:
 - Added Post Traversal Hook and corresponding tests


=== Zope/lib/python/ZPublisher/BaseRequest.py 1.54 => 1.55 ===
--- Zope/lib/python/ZPublisher/BaseRequest.py:1.54	Fri Nov 28 11:46:47 2003
+++ Zope/lib/python/ZPublisher/BaseRequest.py	Wed Mar  3 06:07:01 2004
@@ -252,6 +252,9 @@
 
         request['TraversalRequestNameStack'] = request.path = path
 
+        # Set the posttraverse for duration of the traversal here
+        self._post_traverse = post_traverse = []
+
         entry_name = ''
         try:
             # We build parents in the wrong order, so we
@@ -376,6 +379,9 @@
                 steps.append(entry_name)
         finally:
             parents.reverse()
+ 
+        # After traversal post traversal hooks aren't available anymore
+        del self._post_traverse
 
         request['PUBLISHED'] = parents.pop(0)
 
@@ -449,8 +455,21 @@
         # Remove http request method from the URL.
         request['URL']=URL
 
+        # Run post traversal hooks here
+        result = None
+        if post_traverse:
+            result = exec_callables(post_traverse)
+
+        if result is not None:
+            object = result
+
         return object
 
+    def post_traverse(self, f, args=()):
+        """Set a callable object and argument tuple to be combined if traversal succeeds."""
+        if hasattr(self, "_post_traverse"):
+            self._post_traverse.append((f, tuple(args)))
+
     retry_count=0
     def supports_retry(self): return 0
 
@@ -459,8 +478,13 @@
         """
         self._held=self._held+(object,)
 
-
-
+def exec_callables(callables):
+    result = None
+    for (f, args) in callables:
+        # Don't catch exceptions here. And don't hide them anyway.
+        result = f(*args)
+        if result is not None:
+            return result
 
 def old_validation(groups, request, auth,
                    roles=UNSPECIFIED_ROLES):




More information about the Zope-Checkins mailing list