[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher - BaseRequest.py:1.1.2.7 Exceptions.py:1.1.2.5 Publish.py:1.1.2.7
Shane Hathaway
shane@digicool.com
Mon, 19 Nov 2001 15:25:30 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher
In directory cvs.zope.org:/tmp/cvs-serv21252/lib/python/Zope/Publisher
Modified Files:
Tag: Zope-3x-branch
BaseRequest.py Exceptions.py Publish.py
Log Message:
Reoriented payload objects. They now return the publication object.
Also made Publish.py easier to understand.
=== Zope3/lib/python/Zope/Publisher/BaseRequest.py 1.1.2.6 => 1.1.2.7 ===
common = {} # Data common to all requests
args = () # Positional arguments
- ptype = None # Publishing type
+ publication = None # Publication object
# _held contains objects kept until the request is closed,
# such as the database connection closer.
@@ -43,16 +43,17 @@
# traversed contains the objects traversed in order.
traversed = ()
- def __init__(self, response, body_instream=None):
+ def __init__(self, response, body_instream=None, publication=None):
"""
The constructor should not raise errors.
processInputs() should perform the unsafe initialization.
"""
+ self.response = response
self.body_instream = body_instream
+ self.publication = publication
self.steps = []
self.quoted_steps = []
self.other = {}
- self.response = response
def close(self):
self.other.clear()
@@ -62,6 +63,7 @@
def processInputs(self):
"""Do any input processing that could raise errors
"""
+ return self.publication
def __len__(self):
return 1
=== Zope3/lib/python/Zope/Publisher/Exceptions.py 1.1.2.4 => 1.1.2.5 ===
class Retry (PublishingException):
- """Raise this to retry a request
+ """
+ Raise this to retry a request.
"""
-## def __init__(self, t=None, v=None, tb=None):
-## self._args = t, v, tb
-
-## def reraise(self):
-## t, v, tb = self._args
-## if t is None: t=Retry
-## if tb is None: raise t, v
-## try: raise t, v, tb
-## finally: tb=None
+ def __init__(self, orig_exc=None):
+ self.orig_exc = orig_exc
+ def getOriginalException(self):
+ return self.orig_exc
=== Zope3/lib/python/Zope/Publisher/Publish.py 1.1.2.6 => 1.1.2.7 ===
-def executeRequest(publication, request):
-
- parents = None
+def executeRequest(request):
+ """
+ Either sets the body of the response or raises:
+ - Retry to try the request again
+ - SystemExit to stop publishing
+ - Some other exception if handleException() raised an exception.
+ """
+ publication = None
+ response = request.response
try:
- request.processInputs()
- response = request.response
-
+ publication = request.processInputs()
publication.beforeTraversal(request)
-
+
object = publication.getApplication(request)
path_str = request.get('PATH_INFO', '').strip()
object = request.traverse(publication, object, path_str)
-
publication.afterTraversal(request, object)
result = publication.callObject(request, object)
-
if result is not response:
response.setBody(result)
publication.afterCall(request)
-
- return response
except:
- try:
- exc = sys.exc_info()
- try:
- return publication.handleException(request, exc)
- except Retry:
- # The exception handler requested a retry.
- if not request.supports_retry():
- # Can't retry. Restore the original exception.
- raise exc[0], exc[1], exc[2]
- newrequest = request.retry()
- request.close() # Free resources held by the request.
- try:
- exc = None
- return traverseAndPublish(publication, newrequest)
- finally:
- newrequest.close()
- finally:
- del exc # Avoid circular ref.
+ handleException(sys.exc_info(), request, publication, 1)
+
+
+def handleException(exc_info, request, publication=None, allow_retry=1):
+ if publication is not None:
+ publication.handleException(request, exc_info, allow_retry)
+ else:
+ request.response.handleException(request, exc_info)
+ return exc_info
-def publish(publication, request):
- to_raise = None
+
+
+def publish(request):
try:
- try:
- response = executeRequest(publication, request)
- except SystemExit, v:
- # Output and re-raise
- to_raise = sys.exc_info()
- response = publication.handleException(request, to_raise, 0)
- except:
- # Output but don't re-raise
- exc = sys.exc_info()
+ to_raise = None
+ while 1:
try:
- response = publication.handleException(request, exc, 0)
- finally:
- exc = None # Avoid circ. ref
+ executeRequest(request)
+ # Successful.
+ break
+ except Retry, v:
+ if request.supports_retry():
+ # Create a copy of the request and use it.
+ newrequest = request.retry()
+ request.close()
+ request = newrequest
+ else:
+ # Output the original exception.
+ handleException(v.getOriginalException(), request,
+ publication, 0)
+ except:
+ # Re-raise after outputting the response.
+ to_raise = sys.exc_info()
+ break
+ response = request.response
response.outputBody()
-
- finally:
- if request is not None:
- request.close()
-
- if to_raise is not None:
- try:
+ if to_raise is not None:
raise to_raise[0], to_raise[1], to_raise[2]
- finally:
- to_raise = None
-
- return response.getStatus()
+ return response.getStatus()
+ finally:
+ to_raise = None # Avoid circ. ref.
+ request.close() # Close database connections, etc.