[Zope3-checkins] SVN: Zope3/branches/stephan_and_jim-response-refactor/src/zope/ Made a fairly significant change to the publisher: the publish() method

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Sep 7 11:37:31 EDT 2005


Log message for revision 38341:
  Made a fairly significant change to the publisher: the publish() method 
  now returns the logical request that was actually used to complete the 
  request. This is necessary, since the passed in request might be 
  overridden when a retry of the request occurs.
  
  Also, the request.close() method does not unlink the response object from 
  the request anymore. This allows one to reference the response from the 
  request returned from the publish() method.
  
  This finally corrects the outstanding WSGI issues. All unit and functional 
  tests on this branch pass now.
  
  

Changed:
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/methodnotallowed.txt
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/wsgi/__init__.py
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/publish.py
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/basetestipublicationrequest.py
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/publisherhttpserver.py
  U   Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/tests/test_wsgiserver.py

-=-
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/methodnotallowed.txt
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/methodnotallowed.txt	2005-09-07 14:59:14 UTC (rev 38340)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/methodnotallowed.txt	2005-09-07 15:37:30 UTC (rev 38341)
@@ -10,7 +10,6 @@
   HTTP/1.1 405 Method Not Allowed
   Allow: DELETE, MKCOL, OPTIONS, PROPFIND, PROPPATCH, PUT
   Content-Length: 18
-  Content-Type: text/plain
   <BLANKLINE>
   Method Not Allowed
 

Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/wsgi/__init__.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/wsgi/__init__.py	2005-09-07 14:59:14 UTC (rev 38340)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/wsgi/__init__.py	2005-09-07 15:37:30 UTC (rev 38341)
@@ -41,12 +41,12 @@
     def __call__(self, environ, start_response):
         """See zope.app.wsgi.interfaces.IWSGIApplication"""
         request = self.requestFactory(environ['wsgi.input'], environ)
-        response = request.response
 
         # Let's support post-mortem debugging
         handle_errors = environ.get('wsgi.handleErrors', True)
 
-        publish(request, handle_errors=handle_errors)
+        request = publish(request, handle_errors=handle_errors)
+        response = request.response
 
         # Start the WSGI server response
         start_response(response.getStatusString(), response.getHeaders())

Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py	2005-09-07 14:59:14 UTC (rev 38340)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py	2005-09-07 15:37:30 UTC (rev 38341)
@@ -293,7 +293,6 @@
                 held.release()
 
         self._held = None
-        self._response = None
         self._body_instream = None
         self._publication = None
 

Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py	2005-09-07 14:59:14 UTC (rev 38340)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py	2005-09-07 15:37:30 UTC (rev 38341)
@@ -245,7 +245,7 @@
                           DeprecationWarning,
                           2)
             environ, response = response, outstream
-            
+
         super(HTTPRequest, self).__init__(body_instream, environ, response)
 
         self._orig_env = environ
@@ -562,6 +562,7 @@
 
 
     def __init__(self, header_output=None, http_transaction=None):
+        # XXX BBB
         self._header_output = header_output
 
         super(HTTPResponse, self).__init__()
@@ -760,10 +761,10 @@
         """
         t, v = exc_info[:2]
         if isinstance(t, ClassType):
-            title = tname = t.__name__
             if issubclass(t, Redirect):
                 self.redirect(v.getLocation())
                 return
+            title = tname = t.__name__
         else:
             title = tname = unicode(t)
 
@@ -810,6 +811,7 @@
 
         self.setStatus(status)
         self.setHeader('Location', location)
+        self.setResult(DirectResult(()))
         return location
 
     def _cookie_list(self):

Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/publish.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/publish.py	2005-09-07 14:59:14 UTC (rev 38340)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/publish.py	2005-09-07 15:37:30 UTC (rev 38341)
@@ -186,3 +186,7 @@
     finally:
         to_raise = None  # Avoid circ. ref.
         request.close()  # Close database connections, etc.
+
+    # Return the request, since it might be a different object than the one
+    # that was passed in.
+    return request

Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/basetestipublicationrequest.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/basetestipublicationrequest.py	2005-09-07 14:59:14 UTC (rev 38340)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/basetestipublicationrequest.py	2005-09-07 15:37:30 UTC (rev 38341)
@@ -24,7 +24,7 @@
 
 class Held:
     implements(IHeld)
-    
+
     released = False
 
     def release(self):
@@ -67,7 +67,8 @@
         request.close()
 
         self.failUnless(resource2.released)
-        self.failUnless(sys.getrefcount(response) < rcresponse)
+        # Responses are not unreferenced during close()
+        self.failUnless(sys.getrefcount(response) >= rcresponse)
         self.assertEqual(sys.getrefcount(resource), rcresource)
         self.assertEqual(sys.getrefcount(resource2), rcresource2)
 

Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/publisherhttpserver.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/publisherhttpserver.py	2005-09-07 14:59:14 UTC (rev 38340)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/publisherhttpserver.py	2005-09-07 15:37:30 UTC (rev 38341)
@@ -27,8 +27,8 @@
 
         def application(environ, start_response):
             request = request_factory(environ['wsgi.input'], environ)
+            request = publish(request)
             response = request.response
-            publish(request)
             start_response(response.getStatusString(), response.getHeaders())
             return response.result.body
 
@@ -42,9 +42,8 @@
 
         def application(environ, start_response):
             request = request_factory(environ['wsgi.input'], environ)
-            response = request.response
             try:
-                publish(request, handle_errors=False)
+                request = publish(request, handle_errors=False)
             except:
                 import sys, pdb
                 print "%s:" % sys.exc_info()[0]
@@ -55,12 +54,16 @@
                     raise
                 finally:
                     zope.security.management.endInteraction()
+
+            response = request.response
             start_response(response.getStatusString(), response.getHeaders())
             return response.result.body
 
         return super(PublisherHTTPServer, self).__init__(
             application, sub_protocol, *args, **kw)
 
+
+# BBB: Backward-compatibility.
 zope.deprecation.deprecated(
     ('PublisherHTTPServer', 'PMDBHTTPServer'),
     'This plain publisher support has been replaced in favor of the '

Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/tests/test_wsgiserver.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/tests/test_wsgiserver.py	2005-09-07 14:59:14 UTC (rev 38340)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/tests/test_wsgiserver.py	2005-09-07 15:37:30 UTC (rev 38341)
@@ -104,8 +104,8 @@
         def application(environ, start_response):
             request = BrowserRequest(environ['wsgi.input'], environ)
             request.setPublication(pub)
+            request = publish(request)
             response = request.response
-            publish(request)
             start_response(response.getStatusString(), response.getHeaders())
             return response.result.body
 



More information about the Zope3-Checkins mailing list