Skip to content

Instantly share code, notes, and snippets.

@optilude
Created January 1, 2012 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save optilude/1548061 to your computer and use it in GitHub Desktop.
Save optilude/1548061 to your computer and use it in GitHub Desktop.
Zope 2.13 patch for WSGI ZPublisher events
diff --git a/src/ZPublisher/WSGIPublisher.py b/src/ZPublisher/WSGIPublisher.py
index 5d5b702..02bf7e2 100644
--- a/src/ZPublisher/WSGIPublisher.py
+++ b/src/ZPublisher/WSGIPublisher.py
@@ -13,6 +13,7 @@
""" Python Object Publisher -- Publish Python objects on web servers
"""
from cStringIO import StringIO
+import sys
import time
import transaction
@@ -25,13 +26,19 @@ from ZServer.medusa.http_date import build_http_date
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse
from ZPublisher.mapply import mapply
-from ZPublisher.pubevents import PubBeforeStreaming
from ZPublisher.Publish import call_object
from ZPublisher.Publish import dont_publish_class
from ZPublisher.Publish import get_module_info
from ZPublisher.Publish import missing_name
from ZPublisher.Iterators import IStreamIterator
+from ZPublisher.pubevents import PubStart, PubSuccess, PubFailure, \
+ PubBeforeCommit, PubAfterTraversal, PubBeforeAbort, PubBeforeStreaming
+
+ # XXX: This should really be after transaction abort
+
+
+
_NOW = None # overwrite for testing
def _now():
if _NOW is not None:
@@ -162,6 +169,8 @@ def publish(request, module_name,
transactions_manager,
)= _get_module_info(module_name)
+ notify(PubStart(request))
+
request.processInputs()
response = request.response
@@ -184,6 +193,8 @@ def publish(request, module_name,
request['PARENTS'] = parents = [object]
object = request.traverse(path, validated_hook=validated_hook)
+ notify(PubAfterTraversal(request))
+
if transactions_manager:
transactions_manager.recordMetaData(object, request)
@@ -201,6 +212,8 @@ def publish(request, module_name,
if result is not response:
response.setBody(result)
+ notify(PubBeforeCommit(request))
+
return response
class _RequestCloserForTransaction(object):
@@ -224,6 +237,9 @@ class _RequestCloserForTransaction(object):
def afterCompletion(self, txn):
request = self.requests.pop(txn, None)
if request is not None:
+ if txn.status == 'Committed':
+ notify(PubSuccess(request))
+
request.close()
_request_closer_for_repoze_tm = _RequestCloserForTransaction()
@@ -252,7 +268,16 @@ def publish_module(environ, start_response,
setDefaultSkin(request)
try:
- response = _publish(request, 'Zope2')
+ try:
+ response = _publish(request, 'Zope2')
+ except:
+ exc_info = sys.exc_info()
+ notify(PubBeforeAbort(request, exc_info, request.supports_retry()))
+
+ # XXX: This should really be after transaction abort
+ notify(PubFailure(request, exc_info, request.supports_retry()))
+
+ raise
except Unauthorized, v:
response._unauthorized()
except Redirect, v:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment