[Zope-Checkins] SVN: Zope/branches/2.12/ Added IPubBeforeAbort event to mirror IPubBeforeCommit in failure scenarios.

2009-11-12 Thread Martin Aspeli
Log message for revision 105589:
  Added IPubBeforeAbort event to mirror IPubBeforeCommit in failure scenarios.
  This event is fired just before IPubFailure, but, crucially, while the 
transaction is still open.

Changed:
  U   Zope/branches/2.12/doc/CHANGES.rst
  U   Zope/branches/2.12/src/ZPublisher/Publish.py
  U   Zope/branches/2.12/src/ZPublisher/interfaces.py
  U   Zope/branches/2.12/src/ZPublisher/pubevents.py
  U   Zope/branches/2.12/src/ZPublisher/tests/testpubevents.py

-=-
Modified: Zope/branches/2.12/doc/CHANGES.rst
===
--- Zope/branches/2.12/doc/CHANGES.rst  2009-11-12 21:21:32 UTC (rev 105588)
+++ Zope/branches/2.12/doc/CHANGES.rst  2009-11-13 05:59:41 UTC (rev 105589)
@@ -11,6 +11,10 @@
 Features Added
 ++
 
+- Added IPubBeforeAbort event to mirror IPubBeforeCommit in failure scenarios.
+  This event is fired just before IPubFailure, but, crucially, while the
+  transaction is still open.
+
 - Include bytes limited cache size in the cache parameters ZMI screen.
 
 - Officially supporting Python 2.6 only (with inofficial support for

Modified: Zope/branches/2.12/src/ZPublisher/Publish.py
===
--- Zope/branches/2.12/src/ZPublisher/Publish.py2009-11-12 21:21:32 UTC 
(rev 105588)
+++ Zope/branches/2.12/src/ZPublisher/Publish.py2009-11-13 05:59:41 UTC 
(rev 105589)
@@ -27,7 +27,7 @@
 from zope.event import notify
 
 from pubevents import PubStart, PubSuccess, PubFailure, \
- PubBeforeCommit, PubAfterTraversal
+ PubBeforeCommit, PubAfterTraversal, PubBeforeAbort
 
 class Retry(Exception):
 Raise this to retry a request
@@ -173,8 +173,12 @@
 )
 retry = True
 finally:
+
 # Note: 'abort's can fail. Nevertheless, we want end request 
handling
 try: 
+
+notify(PubBeforeAbort(request, exc_info, retry))
+
 if transactions_manager:
 transactions_manager.abort()
 finally:
@@ -196,6 +200,9 @@
 else:
 # Note: 'abort's can fail. Nevertheless, we want end request 
handling
 try:
+
+notify(PubBeforeAbort(request, exc_info, False))
+
 if transactions_manager:
 transactions_manager.abort()
 finally:

Modified: Zope/branches/2.12/src/ZPublisher/interfaces.py
===
--- Zope/branches/2.12/src/ZPublisher/interfaces.py 2009-11-12 21:21:32 UTC 
(rev 105588)
+++ Zope/branches/2.12/src/ZPublisher/interfaces.py 2009-11-13 05:59:41 UTC 
(rev 105589)
@@ -41,5 +41,12 @@
 
 class IPubBeforeCommit(IPubEvent):
 notified immediately before the transaction commit (i.e. after the main
-request processing is finished.
+request processing is finished).
 
+
+class IPubBeforeAbort(IPubEvent):
+notified immediately before the transaction abort (i.e. after the main
+request processing is finished, and there was an error).
+
+exc_info = Attribute('''The exception info as returned by 
'sys.exc_info()'.''')
+retry = Attribute('Whether the request will be retried')

Modified: Zope/branches/2.12/src/ZPublisher/pubevents.py
===
--- Zope/branches/2.12/src/ZPublisher/pubevents.py  2009-11-12 21:21:32 UTC 
(rev 105588)
+++ Zope/branches/2.12/src/ZPublisher/pubevents.py  2009-11-13 05:59:41 UTC 
(rev 105589)
@@ -10,7 +10,7 @@
 from zope.interface import implements
 
 from interfaces import IPubStart, IPubSuccess, IPubFailure, \
- IPubAfterTraversal, IPubBeforeCommit
+ IPubAfterTraversal, IPubBeforeCommit, IPubBeforeAbort
 
 class _Base(object):
 PubEvent base class.
@@ -42,3 +42,10 @@
 class PubBeforeCommit(_Base):
 notified immediately before the commit.
 implements(IPubBeforeCommit)
+
+class PubBeforeAbort(_Base):
+notified immediately before an abort.
+implements(IPubBeforeAbort)
+
+def __init__(self, request, exc_info, retry):
+self.request, self.exc_info, self.retry = request, exc_info, retry

Modified: Zope/branches/2.12/src/ZPublisher/tests/testpubevents.py
===
--- Zope/branches/2.12/src/ZPublisher/tests/testpubevents.py2009-11-12 
21:21:32 UTC (rev 105588)
+++ Zope/branches/2.12/src/ZPublisher/tests/testpubevents.py2009-11-13 
05:59:41 UTC (rev 105589)
@@ -8,7 +8,7 @@
 from ZPublisher.Publish import publish, Retry
 from ZPublisher.BaseRequest import BaseRequest
 from ZPublisher.pubevents import PubStart, PubSuccess, PubFailure, \
- PubAfterTraversal, PubBeforeCommit
+ PubAfterTraversal, PubBeforeCommit, 

[Zope-Checkins] SVN: Zope/branches/2.12/src/ZPublisher/Publish.py Be a bit more forceful about aborting the transaction

2009-11-12 Thread Martin Aspeli
Log message for revision 105590:
  Be a bit more forceful about aborting the transaction

Changed:
  U   Zope/branches/2.12/src/ZPublisher/Publish.py

-=-
Modified: Zope/branches/2.12/src/ZPublisher/Publish.py
===
--- Zope/branches/2.12/src/ZPublisher/Publish.py2009-11-13 05:59:41 UTC 
(rev 105589)
+++ Zope/branches/2.12/src/ZPublisher/Publish.py2009-11-13 06:42:23 UTC 
(rev 105590)
@@ -175,12 +175,12 @@
 finally:
 
 # Note: 'abort's can fail. Nevertheless, we want end request 
handling
-try: 
-
-notify(PubBeforeAbort(request, exc_info, retry))
-
-if transactions_manager:
-transactions_manager.abort()
+try: 
+try:
+notify(PubBeforeAbort(request, exc_info, retry))
+finally:
+if transactions_manager:
+transactions_manager.abort()
 finally:
 endInteraction()
 notify(PubFailure(request, exc_info, retry))
@@ -198,19 +198,19 @@
 newrequest.close()
 
 else:
+
 # Note: 'abort's can fail. Nevertheless, we want end request 
handling
-try:
-
-notify(PubBeforeAbort(request, exc_info, False))
-
-if transactions_manager:
-transactions_manager.abort()
+try: 
+try:
+notify(PubBeforeAbort(request, exc_info, False))
+finally:
+if transactions_manager:
+transactions_manager.abort()
 finally:
 endInteraction()
-notify(PubFailure(request, exc_info, False))
+notify(PubFailure(request, exc_info, retry))
 raise
 
-
 def publish_module_standard(module_name,
stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr,
environ=os.environ, debug=0, request=None, response=None):

___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins