From 1faa76a86fe170fcab8ddfeb0d069ca10793f8a3 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Tue, 18 Jun 2013 17:53:28 +0100 Subject: [PATCH] Use the new urllib3 stream generator. --- requests/models.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/requests/models.py b/requests/models.py index d894d9f..6600a91 100644 --- a/requests/models.py +++ b/requests/models.py @@ -537,11 +537,18 @@ class Response(object): return iter_slices(self._content, chunk_size) def generate(): - while 1: - chunk = self.raw.read(chunk_size, decode_content=True) - if not chunk: - break - yield chunk + try: + # Special case for urllib3. + for chunk in self.raw.stream(chunk_size, decode_content=True): + yield chunk + except AttributeError: + # Standard file-like object. + while 1: + chunk = self.raw.read(chunk_size, decode_content=True) + if not chunk: + break + yield chunk + self._content_consumed = True gen = generate() -- 2.7.4