[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher - Exceptions.py:1.1.2.13 Publish.py:1.1.2.18

Jim Fulton jim@zope.com
Sun, 28 Apr 2002 13:17:18 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher
In directory cvs.zope.org:/tmp/cvs-serv17050/lib/python/Zope/Publisher

Modified Files:
      Tag: Zope-3x-branch
	Exceptions.py Publish.py 
Log Message:
HOTYB: Merged SecurityProxy-branch into main branch.  

All tests pass and folders can be listed and added through the web.
It is likely that most other things don't work and will need to be
fixed. The reason is that many accesses that should have been checked
before are now being checked and additional checks and thinking about
permissions and security settings are needed.

I'm in the process of drafting a paper for the wiki that describes the
changes in more detail.


=== Zope3/lib/python/Zope/Publisher/Exceptions.py 1.1.2.12 => 1.1.2.13 ===
 
     def __str__(self):
-        return 'Object: %s, name: %s' % (`self.ob`, `self.name`)
+        try: ob = `self.ob`
+        except: ob = 'unprintable object'
+        return 'Object: %s, name: %s' % (ob, `self.name`)
 
 
 class DebugError (TraversalException):


=== Zope3/lib/python/Zope/Publisher/Publish.py 1.1.2.17 => 1.1.2.18 ===
 from Exceptions import Retry
 
-
-def executeRequest(request):
-    """Either sets the body of the response or raises:
-    - Retry to try the request again
-    - SystemExit to stop publishing  (maybe?)
-    - Some other exception if handleException() raised an exception.
-    """
-    
-    publication = request.getPublication()
-    response = request.getResponse()
-
-    try:
-        request.processInputs()
-        publication.beforeTraversal(request)
-
-        root_object = publication.getApplication(request)
-        object = request.traverse(root_object)
-        publication.afterTraversal(request, object)
-
-        result = publication.callObject(request, object)
-        if result is not response:
-            response.setBody(result)
-
-        publication.afterCall(request)
-    except:
-        publication.handleException(request, sys.exc_info(), 1)
-
-
-def publish(request):
-    try:
+def publish(request, handle_errors=1):
+    try: # finally to clean up to_raise and close request
         to_raise = None
         while 1:
+            publication = request.getPublication()
             try:
                 try:
-                    executeRequest(request)
-                    # Successful.
-                    break
+                    try:
+                        request.processInputs()
+                        publication.beforeTraversal(request)
+
+                        root_object = publication.getApplication(request)
+                        object = request.traverse(root_object)
+                        publication.afterTraversal(request, object)
+
+                        result = publication.callObject(request, object)
+                        response = request.getResponse()
+                        if result is not response:
+                            response.setBody(result)
+
+                        publication.afterCall(request)
+
+                    except:
+                        publication.handleException(request, sys.exc_info(), 1)
+                        if not handle_errors:
+                            raise
+                    
+                    break # Successful.
+
                 except Retry, retryException:
                     if request.supportsRetry():
                         # Create a copy of the request and use it.
                         newrequest = request.retry()
                         request.close()
                         request = newrequest
-                    else:
+                    elif handle_errors:
                         # Output the original exception.
                         publication = request.getPublication()
                         publication.handleException(
                             request, retryException.getOriginalException(), 0)
                         break
+                    else:
+                        raise
+                
             except:
                 # Bad exception handler or retry method.
                 # Re-raise after outputting the response.
-                request.getResponse().internalError()
-                to_raise = sys.exc_info()
-                break
+                if handle_errors:
+                    request.getResponse().internalError()
+                    to_raise = sys.exc_info()
+                    break
+                else:
+                    raise
 
         response = request.getResponse()
         response.outputBody()
@@ -85,4 +83,7 @@
     finally:
         to_raise = None  # Avoid circ. ref.
         request.close()  # Close database connections, etc.
+
+
+