summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2005-09-29 20:16:07 +0000
committerGeorg Brandl <georg@python.org>2005-09-29 20:16:07 +0000
commit8670f27d4fa848c1f7290a6e2ac5e39cedb44adb (patch)
treec5a861fb190d23697815dfcb6473f641d18ac51f /Lib
parent1cc03c776e2ecaadfd8e60d04b05cb857c307aaa (diff)
downloadcpython-8670f27d4fa848c1f7290a6e2ac5e39cedb44adb.tar.gz
bug [ 1296004 ] MemoryError in httplib
Diffstat (limited to 'Lib')
-rw-r--r--Lib/httplib.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index e017cdfcd5..5c82edd896 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -153,6 +153,9 @@ HTTP_VERSION_NOT_SUPPORTED = 505
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 @@ class HTTPResponse:
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: