Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bytearray to accumulate bytes from gzip #1468

Merged
merged 2 commits into from Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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