[Zope-Checkins] CVS: Zope/lib/python/ZPublisher -
BaseRequest.py:1.51.14.1
Christian Theune
ct at gocept.com
Sat Oct 4 06:12:34 EDT 2003
Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv7481
Modified Files:
Tag: Zope-2_7-posttraverse
BaseRequest.py
Log Message:
- Committing the post_traversal hook as an alternative branch for 2.7
some ppl need it, but feature freeze is already there.
=== Zope/lib/python/ZPublisher/BaseRequest.py 1.51 => 1.51.14.1 ===
--- Zope/lib/python/ZPublisher/BaseRequest.py:1.51 Fri May 30 11:21:15 2003
+++ Zope/lib/python/ZPublisher/BaseRequest.py Sat Oct 4 06:12:33 2003
@@ -240,6 +240,7 @@
path.reverse()
request['TraversalRequestNameStack'] = request.path = path
+ self._post_traverse = post_traverse = []
entry_name = ''
try:
@@ -372,6 +373,7 @@
parents.reverse()
request['PUBLISHED'] = parents.pop(0)
+ del self._post_traverse
# Do authorization checks
user=groups=None
@@ -432,6 +434,9 @@
elif roles is UNSPECIFIED_ROLES: user=v(request, auth)
else: user=v(request, auth, roles)
+ if post_traverse:
+ exec_callables(post_traverse)
+
if user is None and roles != UNSPECIFIED_ROLES:
response.unauthorized()
@@ -442,7 +447,26 @@
# Remove http request method from the URL.
request['URL']=URL
+ def post_traverse(self, f, args):
+ """Set a callable object and argument tuple to be combined if traversal succeeds"""
+ self._post_traverse.append((f, tuple(args)))
+def exec_callables(callables):
+ for (f, args) in callables:
+ try:
+ f(*args)
+ except (ArithmeticError, AttributeError, FloatingPointError,
+ IOError, ImportError, IndexError, KeyError,
+ OSError, OverflowError, TypeError, ValueError,
+ ZeroDivisionError):
+ # Only catch exceptions that are likely to be logic errors.
+ # We shouldn't catch Redirects, Unauthorizeds, etc. since
+ # the programmer may want to raise them deliberately.
+ from zLOG import LOG, ERROR
+ import sys
+ LOG('PostTraverse', ERROR,
+ 'Error while invoking hook: "%s"' % `f`,
+ error=sys.exc_info())
return object
retry_count=0
More information about the Zope-Checkins
mailing list