From: Cory Benfield Date: Tue, 18 Jun 2013 16:47:23 +0000 (+0100) Subject: Update urllib3 to cffbd6b317 X-Git-Tag: 2.0~19^2~6^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ecf57cac5ce1d9e365b52ded97e59038287c6a9d;p=services%2Fpython-requests.git Update urllib3 to cffbd6b317 --- diff --git a/requests/packages/urllib3/response.py b/requests/packages/urllib3/response.py index 05bc38a..74a5156 100644 --- a/requests/packages/urllib3/response.py +++ b/requests/packages/urllib3/response.py @@ -11,6 +11,7 @@ import io from .exceptions import DecodeError from .packages.six import string_types as basestring, binary_type +from .util import is_fp_closed log = logging.getLogger(__name__) @@ -201,6 +202,29 @@ class HTTPResponse(io.IOBase): if self._original_response and self._original_response.isclosed(): self.release_conn() + def stream(self, amt=2**16, decode_content=None): + """ + A generator wrapper for the read() method. A call will block until + ``amt`` bytes have been read from the connection or until the + connection is closed. + + :param amt: + How much of the content to read. The generator will return up to + much data per iteration, but may return less. This is particularly + likely when using compressed data. However, the empty string will + never be returned. + + :param decode_content: + If True, will attempt to decode the body based on the + 'content-encoding' header. + """ + while not is_fp_closed(self._fp): + data = self.read(amt=amt, decode_content=decode_content) + + if data: + yield data + + @classmethod def from_httplib(ResponseCls, r, **response_kw): """ diff --git a/requests/packages/urllib3/util.py b/requests/packages/urllib3/util.py index 544f9ed..f4eb5e9 100644 --- a/requests/packages/urllib3/util.py +++ b/requests/packages/urllib3/util.py @@ -31,7 +31,6 @@ try: # Test for SSL features except ImportError: pass - from .packages import six from .exceptions import LocationParseError, SSLError @@ -341,6 +340,20 @@ def assert_fingerprint(cert, fingerprint): .format(hexlify(fingerprint_bytes), hexlify(cert_digest))) +def is_fp_closed(obj): + """ + Checks whether a given file-like object is closed. + + :param obj: + The file-like object to check. + """ + if hasattr(obj, 'fp'): + # Object is a container for another file-like object that gets released + # on exhaustion (e.g. HTTPResponse) + return obj.fp is None + + return obj.closed + if SSLContext is not None: # Python 3.2+ def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,