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 ...@@ -39,6 +39,13 @@ Features Added
Restructuring 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. - Simplified `ZPublisher.WSGIPublisher.get_module_info` contract.
- Add new `ZPublisher.utils.recordMetaData` function and use default - Add new `ZPublisher.utils.recordMetaData` function and use default
......
...@@ -31,7 +31,7 @@ sourcecodegen==0.6.14 ...@@ -31,7 +31,7 @@ sourcecodegen==0.6.14
transaction==1.6.1 transaction==1.6.1
waitress==1.0.0 waitress==1.0.0
z3c.pt==3.0 z3c.pt==3.0
zExceptions==3.3 zExceptions==3.4
zc.lockfile==1.2.1 zc.lockfile==1.2.1
zdaemon==4.1.0 zdaemon==4.1.0
zodbpickle==0.6.0 zodbpickle==0.6.0
......
...@@ -67,7 +67,7 @@ setup( ...@@ -67,7 +67,7 @@ setup(
'sourcecodegen', 'sourcecodegen',
'transaction', 'transaction',
'waitress', 'waitress',
'zExceptions >= 3.2', 'zExceptions >= 3.4',
'z3c.pt', 'z3c.pt',
'zope.browser', 'zope.browser',
'zope.browsermenu', 'zope.browsermenu',
......
...@@ -1195,7 +1195,7 @@ class HTTPRequest(BaseRequest): ...@@ -1195,7 +1195,7 @@ class HTTPRequest(BaseRequest):
# method is called on the response). # method is called on the response).
try: try:
object = req.traverse(path) object = req.traverse(path)
except: except Exception:
rsp.exception() rsp.exception()
if object is None: if object is None:
req.clear() req.clear()
......
This diff is collapsed.
...@@ -167,11 +167,12 @@ def _publish_response(request, response, module_info, _publish=publish): ...@@ -167,11 +167,12 @@ def _publish_response(request, response, module_info, _publish=publish):
try: try:
with transaction_pubevents(request): with transaction_pubevents(request):
response = _publish(request, module_info) 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: 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') view = queryMultiAdapter((exc, request), name=u'index.html')
if view is not None: if view is not None:
parents = request.get('PARENTS') parents = request.get('PARENTS')
...@@ -181,8 +182,7 @@ def _publish_response(request, response, module_info, _publish=publish): ...@@ -181,8 +182,7 @@ def _publish_response(request, response, module_info, _publish=publish):
response.setBody(view()) response.setBody(view())
return response return response
if isinstance(exc, Unauthorized): if isinstance(exc, (HTTPRedirection, Unauthorized)):
response._unauthorized(exc)
return response return response
raise raise
......
...@@ -469,7 +469,7 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup): ...@@ -469,7 +469,7 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup):
start_response._called_with[0][0], '500 Internal Server Error') start_response._called_with[0][0], '500 Internal Server Error')
self.assertTrue('Exception View: InternalError' in body) self.assertTrue('Exception View: InternalError' in body)
def testRedirectNoExceptionView(self): def testRedirectExceptionView(self):
from zExceptions import Redirect from zExceptions import Redirect
registerExceptionView(IException) registerExceptionView(IException)
environ = self._makeEnviron() environ = self._makeEnviron()
...@@ -478,9 +478,9 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup): ...@@ -478,9 +478,9 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup):
_publish._raise = Redirect('http://localhost:9/') _publish._raise = Redirect('http://localhost:9/')
app_iter = self._callFUT(environ, start_response, _publish) app_iter = self._callFUT(environ, start_response, _publish)
body = ''.join(app_iter) body = ''.join(app_iter)
self.assertEqual(body, '')
status, headers = start_response._called_with[0] status, headers = start_response._called_with[0]
self.assertEqual(status, '302 Found') self.assertEqual(status, '302 Found')
self.assertTrue('Exception View: Redirect' in body)
headers = dict(headers) headers = dict(headers)
self.assertEqual(headers['Location'], 'http://localhost:9/') self.assertEqual(headers['Location'], 'http://localhost:9/')
......
...@@ -35,7 +35,7 @@ zc.lockfile = 1.2.1 ...@@ -35,7 +35,7 @@ zc.lockfile = 1.2.1
ZConfig = 3.1.0 ZConfig = 3.1.0
zdaemon = 4.1.0 zdaemon = 4.1.0
ZEO = 5.0.1 ZEO = 5.0.1
zExceptions = 3.3 zExceptions = 3.4
ZODB = 5.0.0 ZODB = 5.0.0
zodbpickle = 0.6.0 zodbpickle = 0.6.0
zope.annotation = 4.4.1 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