[Python-checkins] python/dist/src/Lib httplib.py,1.95,1.96

birkenfeld@users.sourceforge.net birkenfeld at users.sourceforge.net
Thu Sep 29 22:16:10 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7050/Lib

Modified Files:
	httplib.py 
Log Message:
bug [ 1296004 ] MemoryError in httplib



Index: httplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/httplib.py,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- httplib.py	26 Jun 2005 22:06:54 -0000	1.95
+++ httplib.py	29 Sep 2005 20:16:07 -0000	1.96
@@ -153,6 +153,9 @@
 INSUFFICIENT_STORAGE = 507
 NOT_EXTENDED = 510
 
+# maximal amount of data to read at one time in _safe_read
+MAXAMOUNT = 1048576
+
 class HTTPMessage(mimetools.Message):
 
     def addheader(self, key, value):
@@ -541,14 +544,14 @@
         reading. If the bytes are truly not available (due to EOF), then the
         IncompleteRead exception can be used to detect the problem.
         """
-        s = ''
+        s = []
         while amt > 0:
-            chunk = self.fp.read(amt)
+            chunk = self.fp.read(min(amt, MAXAMOUNT))
             if not chunk:
                 raise IncompleteRead(s)
-            s += chunk
+            s.append(chunk)
             amt -= len(chunk)
-        return s
+        return ''.join(s)
 
     def getheader(self, name, default=None):
         if self.msg is None:



More information about the Python-checkins mailing list