Skip to content

Commit

Permalink
WSGIPublisher: normalize http exception classes
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli authored and hannosch committed Feb 5, 2017
1 parent 213e8ab commit 8cf7a00
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGES.rst
Expand Up @@ -20,6 +20,13 @@ Bugs Fixed
- Don't copy items the user is not allowed to view.
From Products.PloneHotfix20161129. [maurits]

- Make the WSGIPublisher normalize HTTP exception classes based on name
(for example, any exception named NotFound will be converted
into `zExceptions.NotFound`). This restores compatibility with
similar behavior of the old publisher.
[davisagli]


Features Added
++++++++++++++

Expand Down
1 change: 1 addition & 0 deletions buildout.cfg
Expand Up @@ -19,6 +19,7 @@ parts =
requirements
sources-dir = develop
auto-checkout =
zExceptions


[test]
Expand Down
2 changes: 1 addition & 1 deletion sources.cfg
Expand Up @@ -14,7 +14,7 @@ five.globalrequest = git ${remotes:github}/five.globalrequest pushurl=${remotes:
MultiMapping = git ${remotes:github}/MultiMapping pushurl=${remotes:github_push}/MultiMapping
Persistence = git ${remotes:github}/Persistence pushurl=${remotes:github_push}/Persistence
RestrictedPython = git ${remotes:github}/RestrictedPython pushurl=${remotes:github_push}/RestrictedPython
zExceptions = git ${remotes:github}/zExceptions pushurl=${remotes:github_push}/zExceptions
zExceptions = git ${remotes:github}/zExceptions pushurl=${remotes:github_push}/zExceptions branch=davisagli-upgradeException
zope.globalrequest = git ${remotes:github}/zope.globalrequest pushurl=${remotes:github_push}/zope.globalrequest

# Optional dependencies
Expand Down
7 changes: 7 additions & 0 deletions src/ZPublisher/WSGIPublisher.py
Expand Up @@ -26,6 +26,7 @@
HTTPOk,
HTTPRedirection,
Unauthorized,
upgradeException,
)
from ZODB.POSException import ConflictError
from zope.component import queryMultiAdapter
Expand Down Expand Up @@ -169,6 +170,12 @@ def _publish_response(request, response, module_info, _publish=publish):
with transaction_pubevents(request):
response = _publish(request, module_info)
except Exception as exc:
# Normalize HTTP exceptions
# (For example turn zope.publisher NotFound into zExceptions NotFound)
t, v = upgradeException(exc.__class__, None)
if t is not exc.__class__:
exc = t(str(exc))

if isinstance(exc, HTTPRedirection):
response._redirect(exc)
elif isinstance(exc, Unauthorized):
Expand Down

0 comments on commit 8cf7a00

Please sign in to comment.