This commit is contained in:
Kenneth Reitz
2012-02-15 02:28:53 -05:00
parent 91ac5ba110
commit 00b13673e3
2 changed files with 13 additions and 8 deletions
+4 -8
View File
@@ -25,8 +25,8 @@ from .exceptions import (
ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,
URLRequired, SSLError)
from .utils import (
get_encoding_from_headers, stream_decode_response_unicode,
stream_decompress, guess_filename, requote_uri, dict_from_string)
get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,
dict_from_string)
from .compat import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, str, bytes, SimpleCookie, is_py3, is_py2
@@ -684,10 +684,7 @@ class Response(object):
else:
gen = generate()
if 'gzip' in self.headers.get('content-encoding', ''):
gen = stream_decompress(gen, mode='gzip')
elif 'deflate' in self.headers.get('content-encoding', ''):
gen = stream_decompress(gen, mode='deflate')
gen = stream_untransfer(gen, self)
if decode_unicode:
gen = stream_decode_response_unicode(gen, self)
@@ -729,7 +726,6 @@ class Response(object):
if pending is not None:
yield pending.rstrip()
@property
def content(self):
"""Content of the response, in bytes."""
@@ -741,7 +737,7 @@ class Response(object):
raise RuntimeError(
'The content for this response was already consumed')
self._content = self.raw.read()
self._content = bytes('').join(self.iter_content()) or None
except AttributeError:
self._content = None
+9
View File
@@ -400,6 +400,15 @@ def stream_decompress(iterator, mode='gzip'):
if rv:
yield rv
def stream_untransfer(gen, resp):
if 'gzip' in resp.headers.get('content-encoding', ''):
gen = stream_decompress(gen, mode='gzip')
elif 'deflate' in resp.headers.get('content-encoding', ''):
gen = stream_decompress(gen, mode='deflate')
return gen
# The unreserved URI characters (RFC 3986)
UNRESERVED_SET = frozenset(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"