Skip to content
Myr

Update urllib3 to 71f84f9.

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

authored by schlamar · committed by schlamar · parent 2426eeb · Browse files · 2 files+54 added−27 removed
This commit

State

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

Diff stats

2 files+54 added−27 removed

  • other:+54 added−27 removed

2 files+54 added−27 removed

modified:requests/packages/urllib3/filepost.py+1 added-1 removed
91 unmodified lines
92 body.write(b'\r\n')9394 body.write(b('--%s--\r\n' % (boundary)))9596 content_type = b('multipart/form-data; boundary=%s' % boundary)96 content_type = str('multipart/form-data; boundary=%s' % boundary)9798 return body.getvalue(), content_type
modified:requests/packages/urllib3/response.py+53 added-26 removed
2 unmodified lines
3#4# This module is part of urllib3 and is released under5# the MIT License: http://www.opensource.org/licenses/mit-license.php67import gzip78import logging9import zlib1011from io import BytesIO1211from .exceptions import DecodeError14from .packages.six import string_types as basestring12from .packages.six import string_types as basestring, binary_type131415log = logging.getLogger(__name__)161720def decode_gzip(data):21 gzipper = gzip.GzipFile(fileobj=BytesIO(data))22 return gzipper.read()18class DeflateDecoder(object):1920 def __init__(self):21 self._first_try = True22 self._data = binary_type()23 self._obj = zlib.decompressobj()2425def decode_deflate(data):26 try:27 return zlib.decompress(data)28 except zlib.error:29 return zlib.decompress(data, -zlib.MAX_WBITS)25 def __getattr__(self, name):26 return getattr(self._obj, name)2728 def decompress(self, data):29 if not self._first_try:30 return self._obj.decompress(data)3132 self._data += data33 try:34 return self._obj.decompress(data)35 except zlib.error:36 self._first_try = False37 self._obj = zlib.decompressobj(-zlib.MAX_WBITS)38 try:39 return self.decompress(self._data)40 finally:41 self._data = None424344def _get_decoder(mode):45 if mode == 'gzip':46 return zlib.decompressobj(16 + zlib.MAX_WBITS)4748 return DeflateDecoder()495051class HTTPResponse(object):52 """53 HTTP Response container.54
15 unmodified lines
70 object, it's convenient to include the original for debug purposes. It's71 otherwise unused.72 """7355 CONTENT_DECODERS = {56 'gzip': decode_gzip,57 'deflate': decode_deflate,58 }74 CONTENT_DECODERS = ['gzip', 'deflate']7576 def __init__(self, body='', headers=None, status=0, version=0, reason=None,77 strict=0, preload_content=True, decode_content=True,78 original_response=None, pool=None, connection=None):
1 unmodified line
80 self.status = status81 self.version = version82 self.reason = reason83 self.strict = strict84 self.decode_content = decode_content8569 self._decode_content = decode_content86 self._decoder = None87 self._body = body if body and isinstance(body, basestring) else None88 self._fp = None89 self._original_response = original_response90
40 unmodified lines
131 Similar to :meth:`httplib.HTTPResponse.read`, but with two additional132 parameters: ``decode_content`` and ``cache_content``.133134 :param amt:118 How much of the content to read. If specified, decoding and caching119 is skipped because we can't decode partial content nor does it make120 sense to cache partial content as the full response.135 How much of the content to read. If specified, caching is skipped136 because it doesn't make sense to cache partial content as the full137 response.138139 :param decode_content:140 If True, will attempt to decode the body based on the124 'content-encoding' header. (Overridden if ``amt`` is set.)141 'content-encoding' header.142143 :param cache_content:144 If True, will save the returned data such that the same result is145 returned despite of the state of the underlying file object. This
3 unmodified lines
149 """150 # Note: content-encoding value should be case-insensitive, per RFC 2616151 # Section 3.5152 content_encoding = self.headers.get('content-encoding', '').lower()136 decoder = self.CONTENT_DECODERS.get(content_encoding)153 if self._decoder is None:154 if content_encoding in self.CONTENT_DECODERS:155 self._decoder = _get_decoder(content_encoding)156 if decode_content is None:138 decode_content = self._decode_content157 decode_content = self.decode_content158159 if self._fp is None:160 return161162 flush_decoder = False163164 try:165 if amt is None:166 # cStringIO doesn't like amt=None167 data = self._fp.read()168 flush_decoder = True169 else:170 cache_content = False171 data = self._fp.read(amt)172 if amt != 0 and not data: # Platform-specific: Buggy versions of Python.173 # Close the connection when no data is returned174 #
2 unmodified lines
177 # December 15, 2012 (http://bugs.python.org/issue16298) do not178 # properly close the connection in all cases. There is no harm179 # in redundantly calling close.180 self._fp.close()158 return data181 flush_decoder = True182183 try:161 if decode_content and decoder:162 data = decoder(data)184 if decode_content and self._decoder:185 data = self._decoder.decompress(data)186 except (IOError, zlib.error):187 raise DecodeError("Received response with content-encoding: %s, but "188 "failed to decode it." % content_encoding)189190 if flush_decoder and self._decoder:191 buf = self._decoder.decompress(binary_type())192 data += buf + self._decoder.flush()193194 if cache_content:195 self._body = data196197 return data
44 unmodified lines