Skip to content

Commit

Permalink
- simplify this patch
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Apr 27, 2019
1 parent 3063d90 commit f0d4f84
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Testing/ZopeTestCase/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def load_app(module_info):
"""Let the Publisher use the current app object."""
app = AppZapper().app()
if app is not None:
yield app, module_info[1], module_info[2], module_info[3]
yield app, module_info[1], module_info[2]
else:
with ZPublisher.WSGIPublisher.__old_load_app__(module_info) as ret:
yield ret
Expand Down
23 changes: 13 additions & 10 deletions src/ZPublisher/WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def set_default_debug_exceptions(debug_exceptions):
_DEFAULT_DEBUG_EXCEPTIONS = debug_exceptions


def get_debug_exceptions():
global _DEFAULT_DEBUG_EXCEPTIONS
return _DEFAULT_DEBUG_EXCEPTIONS


def set_default_debug_mode(debug_mode):
global _DEFAULT_DEBUG_MODE
_DEFAULT_DEBUG_MODE = debug_mode
Expand All @@ -99,8 +104,7 @@ def get_module_info(module_name='Zope2'):
module = __import__(module_name)
app = getattr(module, 'bobo_application', module)
realm = _DEFAULT_REALM if _DEFAULT_REALM is not None else module_name
_MODULES[module_name] = info = (app, realm, _DEFAULT_DEBUG_MODE,
_DEFAULT_DEBUG_EXCEPTIONS)
_MODULES[module_name] = info = (app, realm, _DEFAULT_DEBUG_MODE)
return info


Expand Down Expand Up @@ -168,8 +172,7 @@ def transaction_pubevents(request, response, tm=transaction.manager):
try:
# Raise exception from app if handle-errors is False
# (set by zope.testbrowser in some cases)
if request.environ.get('x-wsgiorg.throw_errors', False) or \
_DEFAULT_DEBUG_EXCEPTIONS:
if request.environ.get('x-wsgiorg.throw_errors', False):
reraise(*exc_info)

# Handle exception view
Expand All @@ -195,7 +198,8 @@ def transaction_pubevents(request, response, tm=transaction.manager):
if retry:
reraise(*exc_info)

if not (exc_view_created or isinstance(exc, Unauthorized)):
if not (exc_view_created or isinstance(exc, Unauthorized)) or \
getattr(response, 'debug_exceptions', False):
reraise(*exc_info)
finally:
# Avoid traceback / exception reference cycle.
Expand All @@ -205,13 +209,12 @@ def transaction_pubevents(request, response, tm=transaction.manager):


def publish(request, module_info):
obj, realm, debug_mode, debug_exceptions = module_info
obj, realm, debug_mode = module_info

request.processInputs()
response = request.response

if debug_exceptions:
response.debug_exceptions = debug_exceptions
response.debug_exceptions = get_debug_exceptions()

if debug_mode:
response.debug_mode = debug_mode
Expand Down Expand Up @@ -247,12 +250,12 @@ def publish(request, module_info):

@contextmanager
def load_app(module_info):
app_wrapper, realm, debug_mode, debug_exceptions = module_info
app_wrapper, realm, debug_mode = module_info
# Loads the 'OFS.Application' from ZODB.
app = app_wrapper()

try:
yield (app, realm, debug_mode, debug_exceptions)
yield (app, realm, debug_mode)
finally:
if transaction.manager.manager._txn is not None:
# Only abort a transaction, if one exists. Otherwise the
Expand Down
25 changes: 12 additions & 13 deletions src/ZPublisher/tests/test_WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ def test_wo_REMOTE_USER(self):
request._traverse_to = _object
_realm = 'TESTING'
_debug_mode = True
_debug_exceptions = False
returned = self._callFUT(request, (_object, _realm, _debug_mode,
_debug_exceptions))
returned = self._callFUT(request, (_object, _realm, _debug_mode))
self.assertTrue(returned is response)
self.assertTrue(request._processedInputs)
self.assertTrue(response.debug_mode)
Expand All @@ -211,9 +209,7 @@ def test_w_REMOTE_USER(self):
request._traverse_to = _object
_realm = 'TESTING'
_debug_mode = True
_debug_exceptions = False
self._callFUT(request, (_object, _realm, _debug_mode,
_debug_exceptions))
self._callFUT(request, (_object, _realm, _debug_mode))
self.assertEqual(response.realm, None)


Expand Down Expand Up @@ -642,9 +638,6 @@ def testHandleErrorsFalseBypassesExceptionResponse(self):

def testDebugExceptionsBypassesExceptionResponse(self):
from zExceptions import BadRequest
from ZPublisher.WSGIPublisher import set_default_debug_exceptions

set_default_debug_exceptions(True)

# Register an exception view for BadRequest
registerExceptionView(IException)
Expand All @@ -653,13 +646,19 @@ def testDebugExceptionsBypassesExceptionResponse(self):
_publish = DummyCallable()
_publish._raise = BadRequest('debugbypass')

# With debug_mode, the exception view is not called.
# Responses will always have debug_exceptions set
def response_factory(stdout, stderr):
response = DummyResponse()
response.debug_exceptions = True
return response

# With debug_exceptions, the exception view is not called.
with self.assertRaises(BadRequest):
self._callFUT(environ, start_response, _publish)
self._callFUT(environ, start_response, _publish,
_response_factory=response_factory)

# Clean up view registration
unregisterExceptionView(IException)
set_default_debug_exceptions(False)


class ExcViewCreatedTests(ZopeTestCase):
Expand Down Expand Up @@ -734,7 +733,7 @@ def close(self):
class App(object):
_p_jar = Connection()

return (App, 'Zope', False, False)
return (App, 'Zope', False)

def test_open_transaction_is_aborted(self):
load_app = self._getTarget()
Expand Down

0 comments on commit f0d4f84

Please sign in to comment.