Skip to content
Myr

Merge pull request #1425 from Lukasa/stream

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Use new urllib3 'stream' parameter.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 25db83f, 1faa76a · Browse files · 3 files+50 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+50 added−6 removed

  • other:+50 added−6 removed

3 files+50 added−6 removed

modified:requests/packages/urllib3/response.py+24 added
9 unmodified lines
10import io1112from .exceptions import DecodeError13from .packages.six import string_types as basestring, binary_type14from .util import is_fp_closed151617log = logging.getLogger(__name__)18
182 unmodified lines
201 finally:202 if self._original_response and self._original_response.isclosed():203 self.release_conn()204205 def stream(self, amt=2**16, decode_content=None):206 """207 A generator wrapper for the read() method. A call will block until208 ``amt`` bytes have been read from the connection or until the209 connection is closed.210211 :param amt:212 How much of the content to read. The generator will return up to213 much data per iteration, but may return less. This is particularly214 likely when using compressed data. However, the empty string will215 never be returned.216217 :param decode_content:218 If True, will attempt to decode the body based on the219 'content-encoding' header.220 """221 while not is_fp_closed(self._fp):222 data = self.read(amt=amt, decode_content=decode_content)223224 if data:225 yield data226227228 @classmethod229 def from_httplib(ResponseCls, r, **response_kw):230 """231 Given an :class:`httplib.HTTPResponse` instance ``r``, return a
67 unmodified lines
modified:requests/packages/urllib3/util.py+14 added-1 removed
29 unmodified lines
30 from ssl import HAS_SNI # Has SNI?31except ImportError:32 pass333434from .packages import six35from .exceptions import LocationParseError, SSLError3637
301 unmodified lines
339 raise SSLError('Fingerprints did not match. Expected "{0}", got "{1}".'340 .format(hexlify(fingerprint_bytes),341 hexlify(cert_digest)))342343def is_fp_closed(obj):344 """345 Checks whether a given file-like object is closed.346347 :param obj:348 The file-like object to check.349 """350 if hasattr(obj, 'fp'):351 # Object is a container for another file-like object that gets released352 # on exhaustion (e.g. HTTPResponse)353 return obj.fp is None354355 return obj.closed356357358if SSLContext is not None: # Python 3.2+359 def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,360 ca_certs=None, server_hostname=None,361 ssl_version=None):
30 unmodified lines
modified:requests/models.py+12 added-5 removed
535 unmodified lines
536 # simulate reading small chunks of the content537 return iter_slices(self._content, chunk_size)538539 def generate():540 try:541 # Special case for urllib3.542 for chunk in self.raw.stream(chunk_size, decode_content=True):543 yield chunk544 except AttributeError:545 # Standard file-like object.540 while 1:541 chunk = self.raw.read(chunk_size, decode_content=True)542 if not chunk:543 break544 yield chunk546 while 1:547 chunk = self.raw.read(chunk_size, decode_content=True)548 if not chunk:549 break550 yield chunk551552 self._content_consumed = True553554 gen = generate()555
138 unmodified lines