-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix workaround for Django ticket 24240 in Python 3
c3ff8fb used the wrong utility function in its workaround for https://code.djangoproject.com/ticket/24240, providing byte strings only in Python 2. This commit switches to the correct function, and changes a test to use the gzip middleware to show this is really fixed now.
- Loading branch information
Showing
3 changed files
with
13 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import json | ||
import zlib | ||
|
||
|
||
def get_content(response): | ||
if getattr(response, 'streaming', None): | ||
content = b''.join(response.streaming_content) | ||
else: | ||
content = response.content | ||
|
||
# Just in case the response is gzipped | ||
try: | ||
# http://www.zlib.net/manual.html - add 16 to decode only the gzip format | ||
content = zlib.decompress(content, 16+zlib.MAX_WBITS) | ||
except zlib.error: | ||
pass | ||
|
||
content = json.loads(content.decode('utf-8')) | ||
return content |