From: Jason R. Coombs Date: Tue, 4 Mar 2014 21:33:40 +0000 (-0500) Subject: Always honor decode_unicode, even when _content is present. X-Git-Tag: v2.3.0~6^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d289eb22f164e0bc71c81b191c1f00bdd08fe669;p=services%2Fpython-requests.git Always honor decode_unicode, even when _content is present. --HG-- extra : amend_source : 25977a1227b163d49bf2e1aec6aa448e5cd3be8a --- diff --git a/requests/models.py b/requests/models.py index 682cd9e..c55e6ea 100644 --- a/requests/models.py +++ b/requests/models.py @@ -621,10 +621,6 @@ class Response(object): If decode_unicode is True, content will be decoded using the best available encoding based on the response. """ - if self._content_consumed: - # simulate reading small chunks of the content - return iter_slices(self._content, chunk_size) - def generate(): try: # Special case for urllib3. @@ -645,12 +641,17 @@ class Response(object): self._content_consumed = True - gen = generate() + # simulate reading small chunks of the content + reused_chunks = iter_slices(self._content, chunk_size) + + stream_chunks = generate() + + chunks = reused_chunks if self._content_consumed else stream_chunks if decode_unicode: - gen = stream_decode_response_unicode(gen, self) + chunks = stream_decode_response_unicode(chunks, self) - return gen + return chunks def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None): """Iterates over the response data, one line at a time. When