[Zope-Checkins] SVN: Zope/trunk/lib/python/ - Rather nasty fix to work around Zope 3 exceptions that have more than one positional argument on the constructor. Also, pass 'handle_errors' argument used for functional http testing around and use that on raise_standardErrorMessage to decide if we need to care about rendering a full HTML traceback.
Sidnei da Silva
sidnei at enfoldsystems.com
Mon Nov 3 19:30:29 EST 2008
Log message for revision 92767:
- Rather nasty fix to work around Zope 3 exceptions that have more than one positional argument on the constructor. Also, pass 'handle_errors' argument used for functional http testing around and use that on raise_standardErrorMessage to decide if we need to care about rendering a full HTML traceback.
Changed:
U Zope/trunk/lib/python/OFS/SimpleItem.py
U Zope/trunk/lib/python/ZPublisher/Publish.py
U Zope/trunk/lib/python/ZPublisher/Test.py
U Zope/trunk/lib/python/Zope2/App/startup.py
-=-
Modified: Zope/trunk/lib/python/OFS/SimpleItem.py
===================================================================
--- Zope/trunk/lib/python/OFS/SimpleItem.py 2008-11-03 19:31:35 UTC (rev 92766)
+++ Zope/trunk/lib/python/OFS/SimpleItem.py 2008-11-04 00:30:26 UTC (rev 92767)
@@ -20,6 +20,7 @@
$Id$
"""
+import inspect
import warnings
import marshal, re, sys, time
@@ -196,7 +197,7 @@
if hasattr(self, '_v_eek'):
# Stop if there is recursion.
raise error_type, error_value, tb
- self._v_eek=1
+ self._v_eek = 1
if error_name.lower() in ('redirect',):
raise error_type, error_value, tb
@@ -215,15 +216,31 @@
if client is None:
client = self
+
if not REQUEST:
REQUEST = aq_acquire(self, 'REQUEST')
+ 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)
+
+ if not (can_raise and handle_errors):
+ # If we have been asked not to handle errors and we
+ # can't re-raise a transformed exception don't even
+ # bother with transforming the exception into
+ # HTML. Just re-raise the original exception right
+ # away.
+ raise error_type, error_value, tb
+
try:
- if hasattr(client, 'standard_error_message'):
- s=getattr(client, 'standard_error_message')
- else:
- client = aq_parent(client)
- s=getattr(client, 'standard_error_message')
+ s = aq_acquire(client, 'standard_error_message')
+
# For backward compatibility, we pass 'error_name' as
# 'error_type' here as historically this has always
# been a string.
@@ -234,7 +251,7 @@
'error_message': error_message,
'error_log_url': error_log_url}
- if getattr(aq_base(s),'isDocTemp',0):
+ if getattr(aq_base(s), 'isDocTemp', 0):
v = s(client, REQUEST, **kwargs)
elif callable(s):
v = s(**kwargs)
@@ -256,10 +273,16 @@
"event log for full details: %s)")%(
html_quote(sys.exc_info()[1]),
))
+
+ if handle_errors:
+ # If we've been asked to handle errors, just
+ # return the rendered exception and let the
+ # ZPublisher Exception Hook deal with it.
+ return error_type, v, tb
raise error_type, v, tb
finally:
if hasattr(self, '_v_eek'): del self._v_eek
- tb=None
+ tb = None
def manage(self, URL1):
"""
Modified: Zope/trunk/lib/python/ZPublisher/Publish.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/Publish.py 2008-11-03 19:31:35 UTC (rev 92766)
+++ Zope/trunk/lib/python/ZPublisher/Publish.py 2008-11-04 00:30:26 UTC (rev 92767)
@@ -191,6 +191,8 @@
else:
stdout=response.stdout
+ response.handle_errors = debug
+
if request is None:
request=Request(stdin, environ, response)
Modified: Zope/trunk/lib/python/ZPublisher/Test.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/Test.py 2008-11-03 19:31:35 UTC (rev 92766)
+++ Zope/trunk/lib/python/ZPublisher/Test.py 2008-11-04 00:30:26 UTC (rev 92767)
@@ -187,6 +187,9 @@
response=Response(stdout=stdout, stderr=stderr)
else:
stdout=response.stdout
+
+ response.handle_errors = debug
+
if request is None:
request=Request(stdin, environ, response)
# make sure that the request we hand over has the
Modified: Zope/trunk/lib/python/Zope2/App/startup.py
===================================================================
--- Zope/trunk/lib/python/Zope2/App/startup.py 2008-11-03 19:31:35 UTC (rev 92766)
+++ Zope/trunk/lib/python/Zope2/App/startup.py 2008-11-04 00:30:26 UTC (rev 92767)
@@ -255,7 +255,15 @@
REQUEST['AUTHENTICATED_USER'] = AccessControl.User.nobody
try:
- f(client, REQUEST, t, v, traceback, error_log_url=error_log_url)
+ result = f(client, REQUEST, t, v,
+ traceback,
+ error_log_url=error_log_url)
+ if result is not None:
+ t, v, traceback = result
+ response = REQUEST.RESPONSE
+ response.setStatus(t)
+ response.setBody(v)
+ return response
except TypeError:
# Pre 2.6 call signature
f(client, REQUEST, t, v, traceback)
More information about the Zope-Checkins
mailing list