From: Cory Benfield Date: Tue, 18 Jun 2013 16:53:28 +0000 (+0100) Subject: Use the new urllib3 stream generator. X-Git-Tag: 2.0~19^2~6^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1faa76a86fe170fcab8ddfeb0d069ca10793f8a3;p=services%2Fpython-requests.git Use the new urllib3 stream generator. --- 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()