[Zope3-checkins] SVN: Zope3/branches/3.2/src/zope/server/http/ Make sure that the wsgi server actually passes the iterable from the

Jim Fulton jim at zope.com
Tue Dec 20 13:24:49 EST 2005


Log message for revision 40916:
  Make sure that the wsgi server actually passes the iterable from the
  application to the server.
  

Changed:
  U   Zope3/branches/3.2/src/zope/server/http/tests/test_wsgiserver.py
  U   Zope3/branches/3.2/src/zope/server/http/wsgihttpserver.py

-=-
Modified: Zope3/branches/3.2/src/zope/server/http/tests/test_wsgiserver.py
===================================================================
--- Zope3/branches/3.2/src/zope/server/http/tests/test_wsgiserver.py	2005-12-20 18:24:47 UTC (rev 40915)
+++ Zope3/branches/3.2/src/zope/server/http/tests/test_wsgiserver.py	2005-12-20 18:24:48 UTC (rev 40916)
@@ -13,6 +13,7 @@
 
 $Id$
 """
+import StringIO
 import unittest
 from asyncore import socket_map, poll
 from threading import Thread
@@ -107,7 +108,7 @@
             request = publish(request)
             response = request.response
             start_response(response.getStatusString(), response.getHeaders())
-            return response.consumeBody()
+            return response.consumeBodyIter()
 
         td.setThreadCount(4)
         # Bind to any port on localhost.
@@ -187,7 +188,21 @@
         # conflicts.
         self.testResponse(path='/conflict?wait_tries=10', status_expected=409)
 
+    def test_server_uses_iterable(self):
+        # Make sure that the task write method isn't called with a
+        # str or non iterable
+        class FakeTask:
+            getCGIEnvironment = lambda _: {}
+            class request_data:
+                getBodyStream = lambda _: StringIO.StringIO()
+            request_data = request_data()
+            setResponseStatus = appendResponseHeaders = lambda *_: None
 
+            def write(self, v):
+                if isinstance(v, str):
+                    raise TypeError("Should only write iterables")
+                list(v)
+        self.server.executeRequest(FakeTask())
 
 def test_suite():
     loader = unittest.TestLoader()

Modified: Zope3/branches/3.2/src/zope/server/http/wsgihttpserver.py
===================================================================
--- Zope3/branches/3.2/src/zope/server/http/wsgihttpserver.py	2005-12-20 18:24:47 UTC (rev 40915)
+++ Zope3/branches/3.2/src/zope/server/http/wsgihttpserver.py	2005-12-20 18:24:48 UTC (rev 40916)
@@ -60,7 +60,7 @@
             return fakeWrite
 
         # Call the application to handle the request and write a response
-        task.write(''.join(self.application(env, start_response)))
+        task.write(self.application(env, start_response))
 
 
 class PMDBWSGIHTTPServer(WSGIHTTPServer):
@@ -83,7 +83,7 @@
 
         # Call the application to handle the request and write a response
         try:
-            task.write(''.join(self.application(env, start_response)))
+            task.write(self.application(env, start_response))
         except:
             import sys, pdb
             print "%s:" % sys.exc_info()[0]



More information about the Zope3-Checkins mailing list