Commit 665b64e3 authored by Hanno Schlichting's avatar Hanno Schlichting

Separate HTTP and WSGI response classes.

Split a common base class out of them and move ZServer specific logic
onto HTTPResponse without impacting WSGIResponse.

Also change the error generating methods on WSGIResponse to raise
exceptions rather than returning responses. It's the publishers job
to turn them into responses and now they get treated in the same way
as when they get raised directly.
parent c85b579a
......@@ -39,6 +39,13 @@ Features Added
Restructuring
+++++++++++++
- Change the WSGIResponse exception methods to raise exceptions instead
of returning responses. This includes notFoundError, forbiddenError,
debugError, badRequestError, unauthorized and redirect.
- Split a common HTTPBaseResponse base class out of HTTPResponse and
WSGIResponse. Move ZServer specific logic onto HTTPResponse.
- Simplified `ZPublisher.WSGIPublisher.get_module_info` contract.
- Add new `ZPublisher.utils.recordMetaData` function and use default
......
......@@ -31,7 +31,7 @@ sourcecodegen==0.6.14
transaction==1.6.1
waitress==1.0.0
z3c.pt==3.0
zExceptions==3.3
zExceptions==3.4
zc.lockfile==1.2.1
zdaemon==4.1.0
zodbpickle==0.6.0
......
......@@ -67,7 +67,7 @@ setup(
'sourcecodegen',
'transaction',
'waitress',
'zExceptions >= 3.2',
'zExceptions >= 3.4',
'z3c.pt',
'zope.browser',
'zope.browsermenu',
......
......@@ -1195,7 +1195,7 @@ class HTTPRequest(BaseRequest):
# method is called on the response).
try:
object = req.traverse(path)
except:
except Exception:
rsp.exception()
if object is None:
req.clear()
......
This diff is collapsed.
......@@ -167,11 +167,12 @@ def _publish_response(request, response, module_info, _publish=publish):
try:
with transaction_pubevents(request):
response = _publish(request, module_info)
except HTTPRedirection as exc:
# TODO: HTTPOk is only handled by the httpexceptions
# middleware, maybe it should be handled here.
response.redirect(exc)
except Exception as exc:
if isinstance(exc, HTTPRedirection):
response._redirect(exc)
elif isinstance(exc, Unauthorized):
response._unauthorized(exc)
view = queryMultiAdapter((exc, request), name=u'index.html')
if view is not None:
parents = request.get('PARENTS')
......@@ -181,8 +182,7 @@ def _publish_response(request, response, module_info, _publish=publish):
response.setBody(view())
return response
if isinstance(exc, Unauthorized):
response._unauthorized(exc)
if isinstance(exc, (HTTPRedirection, Unauthorized)):
return response
raise
......
......@@ -469,7 +469,7 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup):
start_response._called_with[0][0], '500 Internal Server Error')
self.assertTrue('Exception View: InternalError' in body)
def testRedirectNoExceptionView(self):
def testRedirectExceptionView(self):
from zExceptions import Redirect
registerExceptionView(IException)
environ = self._makeEnviron()
......@@ -478,9 +478,9 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup):
_publish._raise = Redirect('http://localhost:9/')
app_iter = self._callFUT(environ, start_response, _publish)
body = ''.join(app_iter)
self.assertEqual(body, '')
status, headers = start_response._called_with[0]
self.assertEqual(status, '302 Found')
self.assertTrue('Exception View: Redirect' in body)
headers = dict(headers)
self.assertEqual(headers['Location'], 'http://localhost:9/')
......
......@@ -35,7 +35,7 @@ zc.lockfile = 1.2.1
ZConfig = 3.1.0
zdaemon = 4.1.0
ZEO = 5.0.1
zExceptions = 3.3
zExceptions = 3.4
ZODB = 5.0.0
zodbpickle = 0.6.0
zope.annotation = 4.4.1
......
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