summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorChris Withers <chris@simplistix.co.uk>2009-09-04 17:15:46 (GMT)
committerChris Withers <chris@simplistix.co.uk>2009-09-04 17:15:46 (GMT)
commit5a86acb6d643dd798673dbc59f314952a4514b17 (patch)
tree5415ef0643fb7094cc82eff36b304e8f443e3616 /Lib/http
parent04ee867b6dbe0c5002cb5ee45866e8ad73cb636a (diff)
downloadcpython-5a86acb6d643dd798673dbc59f314952a4514b17.zip
cpython-5a86acb6d643dd798673dbc59f314952a4514b17.tar.gz
cpython-5a86acb6d643dd798673dbc59f314952a4514b17.tar.bz2
Fixes issue #6838: use a list to accumulate the value instead of repeatedly concatenating strings.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/client.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index f73cd9e..2418340 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -518,10 +518,7 @@ class HTTPResponse(io.RawIOBase):
def _read_chunked(self, amt):
assert self.chunked != _UNKNOWN
chunk_left = self.chunk_left
- value = b""
-
- # 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()
@@ -534,22 +531,22 @@ class HTTPResponse(io.RawIOBase):
# close the connection as protocol synchronisation is
# probably lost
self.close()
- raise IncompleteRead(value)
+ raise IncompleteRead(b''.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 b''.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 b''.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
@@ -570,7 +567,7 @@ class HTTPResponse(io.RawIOBase):
# we read everything; close the "file"
self.close()
- return value
+ return b''.join(value)
def _safe_read(self, amt):
"""Read the number of bytes requested, compensating for partial reads.