[Zope3-checkins] SVN: Zope3/branches/srichter-twisted-integration/src/zope/publisher/ Switch to using a temporary file. It's better for large amounts of data.

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Apr 14 15:23:04 EDT 2005


Log message for revision 29989:
  Switch to using a temporary file. It's better for large amounts of data.
  
  

Changed:
  U   Zope3/branches/srichter-twisted-integration/src/zope/publisher/http.py
  U   Zope3/branches/srichter-twisted-integration/src/zope/publisher/tests/test_http.py

-=-
Modified: Zope3/branches/srichter-twisted-integration/src/zope/publisher/http.py
===================================================================
--- Zope3/branches/srichter-twisted-integration/src/zope/publisher/http.py	2005-04-14 18:33:48 UTC (rev 29988)
+++ Zope3/branches/srichter-twisted-integration/src/zope/publisher/http.py	2005-04-14 19:23:04 UTC (rev 29989)
@@ -16,11 +16,11 @@
 $Id$
 """
 import re, time, random
-import cStringIO
 from urllib import quote, unquote, splitport
 from types import StringTypes, ClassType
 from cgi import escape
 from Cookie import SimpleCookie
+from tempfile import TemporaryFile
 
 from zope.interface import implements
 
@@ -175,7 +175,7 @@
 
     def __init__(self, stream):
         self.stream = stream
-        self.cacheStream = cStringIO.StringIO()
+        self.cacheStream = TemporaryFile()
 
     def getCacheStream(self):
         self.read()

Modified: Zope3/branches/srichter-twisted-integration/src/zope/publisher/tests/test_http.py
===================================================================
--- Zope3/branches/srichter-twisted-integration/src/zope/publisher/tests/test_http.py	2005-04-14 18:33:48 UTC (rev 29988)
+++ Zope3/branches/srichter-twisted-integration/src/zope/publisher/tests/test_http.py	2005-04-14 19:23:04 UTC (rev 29989)
@@ -60,37 +60,42 @@
     def setUp(self):
         self.stream = HTTPInputStream(StringIO(data))
 
+    def getCacheStreamValue(self):
+        self.stream.cacheStream.seek(0)
+        return self.stream.cacheStream.read()
+
     def testRead(self):
         output = ''
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
         output += self.stream.read(5)
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
         output += self.stream.read()
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
-        self.assertEqual(data, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
+        self.assertEqual(data, self.getCacheStreamValue())
 
     def testReadLine(self):
         output = self.stream.readline()
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
         output += self.stream.readline()
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
         output += self.stream.readline()
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
         output += self.stream.readline()
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
-        self.assertEqual(data, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
+        self.assertEqual(data, self.getCacheStreamValue())
 
     def testReadLines(self):
         output = ''.join(self.stream.readlines(4))
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
         output += ''.join(self.stream.readlines())
-        self.assertEqual(output, self.stream.cacheStream.getvalue())
-        self.assertEqual(data, self.stream.cacheStream.getvalue())
+        self.assertEqual(output, self.getCacheStreamValue())
+        self.assertEqual(data, self.getCacheStreamValue())
 
     def testGetChacheStream(self):
         self.stream.read(5)
-        self.assertEqual(data, self.stream.getCacheStream().getvalue())        
+        self.assertEqual(data, self.stream.getCacheStream().read())        
 
+
 class HTTPTests(unittest.TestCase):
 
     _testEnv =  {



More information about the Zope3-Checkins mailing list