Always honor decode_unicode, even when _content is present.

--HG--
extra : amend_source : 25977a1227b163d49bf2e1aec6aa448e5cd3be8a
This commit is contained in:
Jason R. Coombs
2014-03-04 16:33:40 -05:00
parent c8226f69e1
commit d289eb22f1
+8 -7
View File
@@ -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