Skip to content

Commit

Permalink
Use bytearray to accumulate bytes from gzip (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Nov 1, 2018
1 parent f8d1c78 commit 0aeba3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,8 @@ Changes
dev (master)
------------

* Remove quadratic behavior within ``GzipDecoder.decompress()`` (Issue #1467)

* ... [Short description of non-trivial change.] (Issue #)


Expand Down
8 changes: 4 additions & 4 deletions src/urllib3/response.py
Expand Up @@ -69,9 +69,9 @@ def __getattr__(self, name):
return getattr(self._obj, name)

def decompress(self, data):
ret = b''
ret = bytearray()
if self._state == GzipDecoderState.SWALLOW_DATA or not data:
return ret
return bytes(ret)
while True:
try:
ret += self._obj.decompress(data)
Expand All @@ -81,11 +81,11 @@ def decompress(self, data):
self._state = GzipDecoderState.SWALLOW_DATA
if previous_state == GzipDecoderState.OTHER_MEMBERS:
# Allow trailing garbage acceptable in other gzip clients
return ret
return bytes(ret)
raise
data = self._obj.unused_data
if not data:
return ret
return bytes(ret)
self._state = GzipDecoderState.OTHER_MEMBERS
self._obj = zlib.decompressobj(16 + zlib.MAX_WBITS)

Expand Down

0 comments on commit 0aeba3b

Please sign in to comment.