SVN: r23565 - in trunk/quixote: . server

Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 25 Feb 2004 11:55:18 -0500
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: nascheme
Date: 2004-02-25 11:55:18 -0500 (Wed, 25 Feb 2004)
New Revision: 23565

Modified:
   trunk/quixote/publish.py
   trunk/quixote/server/medusa_http.py
   trunk/quixote/server/twisted_http.py
Log:
Refactor PublishError exception handling.  Move the try/except/else block
from publish() to process_request().  That way, requests will be logged
even if they raise an exception.  This also allows some simplification
to the Medusa and Twisted server code.  (thanks to Jason Sibre for patch)


Modified: trunk/quixote/publish.py
===================================================================
--- trunk/quixote/publish.py	2004-02-25 15:32:06 UTC (rev 23564)
+++ trunk/quixote/publish.py	2004-02-25 16:55:18 UTC (rev 23565)
@@ -505,7 +505,15 @@
         exceptions will be handled here.
         """
         self._set_request(request)
-        output = self.try_publish(request, env.get('PATH_INFO', ''))
+        try:
+            self.parse_request(request)
+            output = self.try_publish(request, env.get('PATH_INFO', ''))
+        except errors.PublishError, exc:
+            # Exit the publishing loop and return a result right away.
+            output = self.finish_interrupted_request(request, exc)
+        except:
+            # Some other exception, generate error messages to the logs, etc.
+            output = self.finish_failed_request(request)
         self.log_request(request)
 
         if (output and
@@ -523,16 +531,8 @@
         output.
         """
         request = self.create_request(stdin, env)
-        try:
-            self.parse_request(request)
-            output = self.process_request(request, env)
-        except errors.PublishError, exc:
-            # Exit the publishing loop and return a result right away.
-            output = self.finish_interrupted_request(request, exc)
-        except:
-            # Some other exception, generate error messages to the logs, etc.
-            output = self.finish_failed_request(request)
-
+        output = self.process_request(request, env)
+        
         # Output results from Response object
         if output:
             request.response.set_body(output)

Modified: trunk/quixote/server/medusa_http.py
===================================================================
--- trunk/quixote/server/medusa_http.py	2004-02-25 15:32:06 UTC (rev 23564)
+++ trunk/quixote/server/medusa_http.py	2004-02-25 16:55:18 UTC (rev 23565)
@@ -16,7 +16,6 @@
 from quixote.http_request import HTTPRequest
 from quixote.http_response import Stream
 from quixote.publish import Publisher
-from quixote.errors import PublishError
 
 
 class StreamProducer:
@@ -98,13 +97,7 @@
 
         stdin = StringIO(data)
         qreq = self.publisher.create_request(stdin, environ)
-        try:
-            self.publisher.parse_request(qreq)
-            output = self.publisher.process_request(qreq, environ)
-        except PublishError, err:
-            output = self.publisher.finish_interrupted_request(qreq, err)
-        except:
-            output = self.publisher.finish_failed_request(qreq)
+        output = self.publisher.process_request(qreq, environ)
 
         qresponse = qreq.response
         if output:

Modified: trunk/quixote/server/twisted_http.py
===================================================================
--- trunk/quixote/server/twisted_http.py	2004-02-25 15:32:06 UTC (rev 23564)
+++ trunk/quixote/server/twisted_http.py	2004-02-25 16:55:18 UTC (rev 23565)
@@ -21,7 +21,6 @@
 
 import quixote
 quixote.enable_ptl()
-from quixote import errors
 from quixote.publish import Publisher
 from quixote.http_response import Stream
 
@@ -49,17 +48,7 @@
         Hope you didn't override it...
         """
         pub = self.publisher
-        try:
-            pub.parse_request(qxrequest)
-            output = pub.process_request(qxrequest, env)
-            # needed for session management!
-            pub.finish_successful_request(qxrequest)
-        except errors.PublishError, exc:
-            # Exit the publishing loop and return a result right away.
-            output = pub.finish_interrupted_request(qxrequest, exc)
-        except:
-            # other exception, generate error messages to logs, etc.
-            output = pub.finish_failed_request(qxrequest)
+        output = pub.process_request(qxrequest, env)
 
         # don't write out the output, just set the response body
         # the calling method will do the rest.