summaryrefslogtreecommitdiffstats
path: root/Lib/httplib.py
diff options
context:
space:
mode:
authorChris Withers <chris@simplistix.co.uk>2009-09-04 16:51:16 (GMT)
committerChris Withers <chris@simplistix.co.uk>2009-09-04 16:51:16 (GMT)
commit49148cf5287e34a399ecfc1958d62d2d83339f64 (patch)
tree254565db9a2dc22f7a45a49c74f8b04b8381d8a7 /Lib/httplib.py
parentcf4a7027446cd66909a025c2901712aadf501dd9 (diff)
downloadcpython-49148cf5287e34a399ecfc1958d62d2d83339f64.zip
cpython-49148cf5287e34a399ecfc1958d62d2d83339f64.tar.gz
cpython-49148cf5287e34a399ecfc1958d62d2d83339f64.tar.bz2
Fixes issue #6838: use a list to accumulate the value instead of repeatedly concatenating strings.
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r--Lib/httplib.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 1f584ef..3566c0e 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -544,10 +544,7 @@ class HTTPResponse:
def _read_chunked(self, amt):
assert self.chunked != _UNKNOWN
chunk_left = self.chunk_left
- value = ''
-
- # XXX This accumulates chunks by repeated string concatenation,
- # which is not efficient as the number or size of chunks gets big.
+ value = []
while True:
if chunk_left is None:
line = self.fp.readline()
@@ -560,22 +557,22 @@ class HTTPResponse:
# close the connection as protocol synchronisation is
# probably lost
self.close()
- raise IncompleteRead(value)
+ raise IncompleteRead(''.join(value))
if chunk_left == 0:
break
if amt is None:
- value += self._safe_read(chunk_left)
+ value.append(self._safe_read(chunk_left))
elif amt < chunk_left:
- value += self._safe_read(amt)
+ value.append(self._safe_read(amt))
self.chunk_left = chunk_left - amt
- return value
+ return ''.join(value)
elif amt == chunk_left:
- value += self._safe_read(amt)
+ value.append(self._safe_read(amt))
self._safe_read(2) # toss the CRLF at the end of the chunk
self.chunk_left = None
- return value
+ return ''.join(value)
else:
- value += self._safe_read(chunk_left)
+ value.append(self._safe_read(chunk_left))
amt -= chunk_left
# we read the whole chunk, get another
@@ -596,7 +593,7 @@ class HTTPResponse:
# we read everything; close the "file"
self.close()
- return value
+ return ''.join(value)
def _safe_read(self, amt):
"""Read the number of bytes requested, compensating for partial reads.