[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Added new endRequest
publication method (hook)
Jim Fulton
jim at zope.com
Sat May 15 14:02:33 EDT 2004
Log message for revision 24721:
Added new endRequest publication method (hook)
This is needed so we can end an interaction when a request is
no-longer used.
-=-
Modified: Zope3/trunk/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/tests/test_zopepublication.py 2004-05-15 17:58:51 UTC (rev 24720)
+++ Zope3/trunk/src/zope/app/publication/tests/test_zopepublication.py 2004-05-15 18:02:32 UTC (rev 24721)
@@ -266,7 +266,8 @@
self.assertEqual(self.request, adapter.request)
def testExceptionResetsResponse(self):
- self.request._response = BrowserResponse(self.request.response._outstream)
+ self.request._response = BrowserResponse(
+ self.request.response._outstream)
self.request.response.setHeader('Content-Type', 'application/pdf')
self.request.response.setCookie('spam', 'eggs')
from ZODB.POSException import ConflictError
@@ -384,6 +385,8 @@
self.assertEqual(self.request.principal.id, 'test.bob')
self.assertEqual(list(queryInteraction().participations),
[self.request])
+ self.publication.endRequest(self.request, ob)
+ self.assertEqual(queryInteraction(), None)
def testTransactionCommitAfterCall(self):
root = self.db.open().root()
@@ -431,6 +434,8 @@
self.publication.afterCall(self.request, bar.foo)
self.assertEqual(txn_info['location'], expected_path)
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ZopePublicationTests),
Modified: Zope3/trunk/src/zope/app/publication/zopepublication.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/zopepublication.py 2004-05-15 17:58:51 UTC (rev 24720)
+++ Zope3/trunk/src/zope/app/publication/zopepublication.py 2004-05-15 18:02:32 UTC (rev 24721)
@@ -151,11 +151,12 @@
txn = get_transaction()
self.annotateTransaction(txn, request, ob)
+ txn.commit()
+
+ def endRequest(self, request, ob):
# Make sure the interaction is ended
endInteraction()
- txn.commit()
-
def annotateTransaction(self, txn, request, ob):
"""Set some useful meta-information on the transaction. This
information is used by the undo framework, for example.
@@ -229,9 +230,6 @@
# It must definitely be aborted.
get_transaction().abort()
- # Make sure the interaction is ended
- endInteraction()
-
# Convert ConflictErrors to Retry exceptions.
if retry_allowed and isinstance(exc_info[1], ConflictError):
tryToLogWarning('ZopePublication',
Modified: Zope3/trunk/src/zope/publisher/base.py
===================================================================
--- Zope3/trunk/src/zope/publisher/base.py 2004-05-15 17:58:51 UTC (rev 24720)
+++ Zope3/trunk/src/zope/publisher/base.py 2004-05-15 18:02:32 UTC (rev 24721)
@@ -482,6 +482,9 @@
def afterCall(self, request, ob):
pass
+ def endRequest(self, request, ob):
+ pass
+
def handleException(self, object, request, exc_info, retry_allowed=1):
# Let the response handle it as best it can.
request.response.reset()
Modified: Zope3/trunk/src/zope/publisher/interfaces/__init__.py
===================================================================
--- Zope3/trunk/src/zope/publisher/interfaces/__init__.py 2004-05-15 17:58:51 UTC (rev 24720)
+++ Zope3/trunk/src/zope/publisher/interfaces/__init__.py 2004-05-15 18:02:32 UTC (rev 24721)
@@ -270,7 +270,11 @@
exc_info must be set to some other value before exiting the method.
"""
+ def endRequest(request, ob):
+ """Do any end-of-request cleanup
+ """
+
class IApplicationResponse(Interface):
"""Features that support application logic
"""
Modified: Zope3/trunk/src/zope/publisher/publish.py
===================================================================
--- Zope3/trunk/src/zope/publisher/publish.py 2004-05-15 17:58:51 UTC (rev 24720)
+++ Zope3/trunk/src/zope/publisher/publish.py 2004-05-15 18:02:32 UTC (rev 24721)
@@ -127,26 +127,29 @@
try:
object = None
try:
- request.processInputs()
- publication.beforeTraversal(request)
+ try:
+ request.processInputs()
+ publication.beforeTraversal(request)
- object = publication.getApplication(request)
- object = request.traverse(object)
- publication.afterTraversal(request, object)
+ object = publication.getApplication(request)
+ object = request.traverse(object)
+ publication.afterTraversal(request, object)
- result = publication.callObject(request, object)
- response = request.response
- if result is not response:
- response.setBody(result)
+ result = publication.callObject(request, object)
+ response = request.response
+ if result is not response:
+ response.setBody(result)
- publication.afterCall(request, object)
+ publication.afterCall(request, object)
- except:
- publication.handleException(
- object, request, sys.exc_info(), True)
+ except:
+ publication.handleException(
+ object, request, sys.exc_info(), True)
- if not handle_errors:
- raise
+ if not handle_errors:
+ raise
+ finally:
+ publication.endRequest(request, object)
break # Successful.
Modified: Zope3/trunk/src/zope/publisher/tests/publication.py
===================================================================
--- Zope3/trunk/src/zope/publisher/tests/publication.py 2004-05-15 17:58:51 UTC (rev 24720)
+++ Zope3/trunk/src/zope/publisher/tests/publication.py 2004-05-15 18:02:32 UTC (rev 24721)
@@ -26,6 +26,10 @@
'''See interface IPublication'''
self._afterCall = getattr(self, '_afterCall', 0) + 1
+ def endRequest(self, request, ob):
+ '''See interface IPublication'''
+ self._endRequest = getattr(self, '_endRequest', 0) + 1
+
def traverseName(self, request, ob, name, check_auth=1):
'''See interface IPublication'''
return getattr(ob, name, "%s value" % name)
Modified: Zope3/trunk/src/zope/server/ftp/tests/test_publisher.py
===================================================================
--- Zope3/trunk/src/zope/server/ftp/tests/test_publisher.py 2004-05-15 17:58:51 UTC (rev 24720)
+++ Zope3/trunk/src/zope/server/ftp/tests/test_publisher.py 2004-05-15 18:02:32 UTC (rev 24721)
@@ -54,6 +54,9 @@
def afterCall(self, request, ob):
pass
+ def endRequest(self, request, ob):
+ pass
+
def handleException(self, object, request, info, retry_allowed=True):
request.response._exc = info[:2]
More information about the Zope3-Checkins
mailing list