Commit 79c2dbd4 authored by Sidnei da Silva's avatar Sidnei da Silva

- Rather nasty fix to work around Zope 3 exceptions that have more than one...

 - 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.
parent 78a6c1ba
...@@ -20,6 +20,7 @@ item types. ...@@ -20,6 +20,7 @@ item types.
$Id$ $Id$
""" """
import inspect
import warnings import warnings
import marshal, re, sys, time import marshal, re, sys, time
...@@ -196,7 +197,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -196,7 +197,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
if hasattr(self, '_v_eek'): if hasattr(self, '_v_eek'):
# Stop if there is recursion. # Stop if there is recursion.
raise error_type, error_value, tb raise error_type, error_value, tb
self._v_eek=1 self._v_eek = 1
if error_name.lower() in ('redirect',): if error_name.lower() in ('redirect',):
raise error_type, error_value, tb raise error_type, error_value, tb
...@@ -215,15 +216,31 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -215,15 +216,31 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
if client is None: if client is None:
client = self client = self
if not REQUEST: if not REQUEST:
REQUEST = aq_acquire(self, '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: try:
if hasattr(client, 'standard_error_message'): s = aq_acquire(client, 'standard_error_message')
s=getattr(client, 'standard_error_message')
else:
client = aq_parent(client)
s=getattr(client, 'standard_error_message')
# For backward compatibility, we pass 'error_name' as # For backward compatibility, we pass 'error_name' as
# 'error_type' here as historically this has always # 'error_type' here as historically this has always
# been a string. # been a string.
...@@ -234,7 +251,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -234,7 +251,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
'error_message': error_message, 'error_message': error_message,
'error_log_url': error_log_url} '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) v = s(client, REQUEST, **kwargs)
elif callable(s): elif callable(s):
v = s(**kwargs) v = s(**kwargs)
...@@ -256,10 +273,16 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -256,10 +273,16 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
"event log for full details: %s)")%( "event log for full details: %s)")%(
html_quote(sys.exc_info()[1]), 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 raise error_type, v, tb
finally: finally:
if hasattr(self, '_v_eek'): del self._v_eek if hasattr(self, '_v_eek'): del self._v_eek
tb=None tb = None
def manage(self, URL1): def manage(self, URL1):
""" """
......
...@@ -191,6 +191,8 @@ def publish_module_standard(module_name, ...@@ -191,6 +191,8 @@ def publish_module_standard(module_name,
else: else:
stdout=response.stdout stdout=response.stdout
response.handle_errors = debug
if request is None: if request is None:
request=Request(stdin, environ, response) request=Request(stdin, environ, response)
......
...@@ -187,6 +187,9 @@ def publish_module(module_name, ...@@ -187,6 +187,9 @@ def publish_module(module_name,
response=Response(stdout=stdout, stderr=stderr) response=Response(stdout=stdout, stderr=stderr)
else: else:
stdout=response.stdout stdout=response.stdout
response.handle_errors = debug
if request is None: if request is None:
request=Request(stdin, environ, response) request=Request(stdin, environ, response)
# make sure that the request we hand over has the # make sure that the request we hand over has the
......
...@@ -255,7 +255,15 @@ class ZPublisherExceptionHook: ...@@ -255,7 +255,15 @@ class ZPublisherExceptionHook:
REQUEST['AUTHENTICATED_USER'] = AccessControl.User.nobody REQUEST['AUTHENTICATED_USER'] = AccessControl.User.nobody
try: 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: except TypeError:
# Pre 2.6 call signature # Pre 2.6 call signature
f(client, REQUEST, t, v, traceback) f(client, REQUEST, t, v, traceback)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment