[Zope3-checkins] SVN: Zope3/branches/3.2/src/zope/app/twisted/ Fixed a bug in the twisted prebuffering. The mmap wrapper has some

Jim Fulton jim at zope.com
Sat Dec 31 14:29:22 EST 2005


Log message for revision 41058:
  Fixed a bug in the twisted prebuffering.  The mmap wrapper has some
  problems.  We avoid those by just not using it.
  

Changed:
  U   Zope3/branches/3.2/src/zope/app/twisted/http.py
  U   Zope3/branches/3.2/src/zope/app/twisted/tests/test_inputbuffering.py

-=-
Modified: Zope3/branches/3.2/src/zope/app/twisted/http.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/twisted/http.py	2005-12-30 13:48:38 UTC (rev 41057)
+++ Zope3/branches/3.2/src/zope/app/twisted/http.py	2005-12-31 19:29:21 UTC (rev 41058)
@@ -38,7 +38,7 @@
             def done(_):
                 temp.seek(0)
                 # Replace the request's stream object with the tempfile
-                req.stream = stream.FileStream(temp)
+                req.stream = stream.FileStream(temp, useMMap=False)
                 # Hm, this shouldn't be required:
                 req.stream.doStartReading = None
 

Modified: Zope3/branches/3.2/src/zope/app/twisted/tests/test_inputbuffering.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/twisted/tests/test_inputbuffering.py	2005-12-30 13:48:38 UTC (rev 41057)
+++ Zope3/branches/3.2/src/zope/app/twisted/tests/test_inputbuffering.py	2005-12-31 19:29:21 UTC (rev 41058)
@@ -13,8 +13,10 @@
 ##############################################################################
 r"""Meke sure that input is buffered
 
-Meke sure that input is buffered, so that a slow client doesn't block an application thread.
+Meke sure that input is buffered, so that a slow client doesn't block
+an application thread.
 
+Also, test that both small and (somewhat) large inputs are handled correctly.
 
     >>> instance = Instance()
     >>> instance.start()
@@ -29,7 +31,7 @@
     >>> bad.sendall('Content-Length: 10\r\n')
     >>> bad.sendall('Content-Type: text/plain\r\n')
     >>> bad.sendall('\r\n')
-    >>> bad.sendall('x')
+    >>> bad.sendall('x\r\n')
 
 At this point, the request shouldn't be in a thread yet, so we should be
 able to make another request:
@@ -39,22 +41,22 @@
     >>> s.connect(('localhost', instance.port))
     >>> s.sendall('GET http://localhost:%s/echo HTTP/1.1\r\n'
     ...           % instance.port)
-    >>> s.sendall('Content-Length: 10\r\n')
+    >>> s.sendall('Content-Length: 120005\r\n')
     >>> s.sendall('Content-Type: text/plain\r\n')
     >>> s.sendall('\r\n')
-    >>> s.sendall('xxxxxxxxxxxxxxx\n')
+    >>> s.sendall('xxxxxxxxxx\r\n' * 10000 + 'end\r\n')
     >>> f = s.makefile()
     >>> f.readline()
     'HTTP/1.1 200 OK\r\n'
 
     >>> message = rfc822.Message(f)
     >>> message['content-length']
-    '10'
+    '120000'
 
     >>> s.close()
 
 
-    >>> bad.sendall('xxxxxxxxxx\n')
+    >>> bad.sendall('end\r\n' + 'xxxxxxxxxx\n')
     >>> bad.close()
     >>> instance.stop()
     >>> shutil.rmtree(instance.dir)
@@ -81,7 +83,17 @@
         self.request = request
 
     def echo(self):
-        return self.request.bodyStream.read()
+        s = 0
+        result = []
+        while 1:
+            l = self.request.bodyStream.readline()
+            s += len(l)
+            if l and l != 'end\r\n':
+                result.append(l)
+            else:
+                break
+            
+        return ''.join(result)
     
 
 



More information about the Zope3-Checkins mailing list