simplify
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 91ac5ba · Browse files · 2 files·+13 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+13 added−8 removed
- other:+13 added−8 removed
Provenance
- Commit
00b1367- Tree
0188734- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
91ac5ba
2 files changed+13 added−8 removed
modified:requests/models.py+4 added-8 removed
23 unmodified lines24 from .exceptions import (25 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,26 URLRequired, SSLError)27 from .utils import (28- get_encoding_from_headers, stream_decode_response_unicode,29- stream_decompress, guess_filename, requote_uri, dict_from_string)28+ get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,29+ dict_from_string)30 31 from .compat import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, str, bytes, SimpleCookie, is_py3, is_py232 33 # Import chardet if it is available.649 unmodified lines683 gen = generate_chunked()684 else:685 gen = generate()686 687- if 'gzip' in self.headers.get('content-encoding', ''):688- gen = stream_decompress(gen, mode='gzip')689- elif 'deflate' in self.headers.get('content-encoding', ''):690- gen = stream_decompress(gen, mode='deflate')687+ gen = stream_untransfer(gen, self)688 689 if decode_unicode:690 gen = stream_decode_response_unicode(gen, self)691 33 unmodified lines725 # Yield the last line726 if pending is not None:727 yield pending.rstrip()728 732-729 @property730 def content(self):731 """Content of the response, in bytes."""732 3 unmodified lines736 if self._content_consumed:737 raise RuntimeError(738 'The content for this response was already consumed')739 744- self._content = self.raw.read()740+ self._content = bytes('').join(self.iter_content()) or None741 except AttributeError:742 self._content = None743 744 self._content_consumed = True50 unmodified linesmodified:requests/utils.py+9 added
398 unmodified lines399 rv = buf + dec.flush()400 if rv:401 yield rv402 403+def stream_untransfer(gen, resp):404+ if 'gzip' in resp.headers.get('content-encoding', ''):405+ gen = stream_decompress(gen, mode='gzip')406+ elif 'deflate' in resp.headers.get('content-encoding', ''):407+ gen = stream_decompress(gen, mode='deflate')408+409+ return gen410+411+412 # The unreserved URI characters (RFC 3986)413 UNRESERVED_SET = frozenset(414 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"415 + "0123456789-._~")30 unmodified lines