Merge pull request #2444 from Yasumoto/urllib_upgrade
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Upgrade urllib3 to 490d3a227fadb626cd54a240b9d0922f849914b4
authored by Ian Cordasco · committed by Ian Cordasco · parents 6f3c91b, 62df872 · Browse files · 5 files·+79 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+79 added−11 removed
- other:+79 added−11 removed
Provenance
- Commit
0b6d2e4- Tree
44aa6ab- Author
Ian Cordasco <sigmavirus24@users.noreply.github.com>- Committer
Ian Cordasco <sigmavirus24@users.noreply.github.com>- Parent 1
6f3c91b- Parent 2
62df872
5 files changed+79 added−11 removed
modified:requests/packages/urllib3/util/ssl_.py+6 added-3 removed
1 from binascii import hexlify, unhexlify2-from hashlib import md5, sha12+from hashlib import md5, sha1, sha2563 4 from ..exceptions import SSLError5 6 88 unmodified lines95 # Maps the length of a digest to a possible hash function producing96 # this digest.97 hashfunc_map = {98 16: md5,99- 20: sha199+ 20: sha1,100+ 32: sha256,101 }102 103 fingerprint = fingerprint.replace(':', '').lower()104 digest_length, odd = divmod(len(fingerprint), 2)106 unmodified lines211 context.set_ciphers(ciphers or _DEFAULT_CIPHERS)212 213 context.verify_mode = cert_reqs214 if getattr(context, 'check_hostname', None) is not None: # Platform-specific: Python 3.2214- context.check_hostname = (context.verify_mode == ssl.CERT_REQUIRED)215+ # We do our own verification, including fingerprints and alternative216+ # hostnames. So disable it here217+ context.check_hostname = False218 return context219 220 221 def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,36 unmodified linesmodified:requests/packages/urllib3/_collections.py+11 added-3 removed
1 from collections import Mapping, MutableMapping2 try:3 from threading import RLock4-except ImportError: # Platform-specific: No threads available4+except ImportError: # Platform-specific: No threads available5 class RLock:6 def __enter__(self):7 pass8 9 def __exit__(self, exc_type, exc_value, traceback):10 pass11 12 13-try: # Python 2.7+13+try: # Python 2.7+14 from collections import OrderedDict15 except ImportError:16 from .packages.ordered_dict import OrderedDict17 from .packages.six import iterkeys, itervalues142 unmodified lines160 161 def getlist(self, key):162 """Returns a list of all the values for the named field. Returns an163 empty list if the key doesn't exist."""164- return self[key].split(', ') if key in self else []164+ return [v for k, v in self._data.get(key.lower(), [])]165 166 def copy(self):167 h = HTTPHeaderDict()168 for key in self._data:26 unmodified lines195 yield headers[0][0]196 197 def __repr__(self):198 return '%s(%r)' % (self.__class__.__name__, dict(self.items()))199+200+ def update(self, *args, **kwds):201+ headers = args[0]202+ if isinstance(headers, HTTPHeaderDict):203+ for key in iterkeys(headers._data):204+ self._data.setdefault(key.lower(), []).extend(headers._data[key])205+ else:206+ super(HTTPHeaderDict, self).update(*args, **kwds)modified:requests/packages/urllib3/connectionpool.py+24 added-1 removed
70 unmodified lines71 def __str__(self):72 return '%s(host=%r, port=%r)' % (type(self).__name__,73 self.host, self.port)74 75+ def __enter__(self):76+ return self77+78+ def __exit__(self, exc_type, exc_val, exc_tb):79+ self.close()80+ # Return False to re-raise any potential exceptions81+ return False82+83+ def close():84+ """85+ Close all pooled connections and disable the pool.86+ """87+ pass88+89+90 # This is taken from http://hg.python.org/cpython/file/7aaba721ebc0/Lib/socket.py#l25291 _blocking_errnos = set([errno.EAGAIN, errno.EWOULDBLOCK])92 93 273 unmodified lines367 conn.sock.settimeout(read_timeout)368 369 # Receive the response from the server370 try:356- try: # Python 2.7+, use buffering of HTTP responses371+ try: # Python 2.7, use buffering of HTTP responses372 httplib_response = conn.getresponse(buffering=True)373 except TypeError: # Python 2.6 and older374 httplib_response = conn.getresponse()375 except (SocketTimeout, BaseSSLError, SocketError) as e:196 unmodified lines572 conn.close()573 conn = None574 raise SSLError(e)575 576+ except SSLError:577+ # Treat SSLError separately from BaseSSLError to preserve578+ # traceback.579+ if conn:580+ conn.close()581+ conn = None582+ raise583+584 except (TimeoutError, HTTPException, SocketError, ConnectionError) as e:585 if conn:586 # Discard the connection for these exceptions. It will be587 # be replaced during the next _get_conn() call.210 unmodified linesmodified:requests/packages/urllib3/poolmanager.py+8 added
62 unmodified lines63 self.connection_pool_kw = connection_pool_kw64 self.pools = RecentlyUsedContainer(num_pools,65 dispose_func=lambda p: p.close())66 67+ def __enter__(self):68+ return self69+70+ def __exit__(self, exc_type, exc_val, exc_tb):71+ self.clear()72+ # Return False to re-raise any potential exceptions73+ return False74+75 def _new_pool(self, scheme, host, port):76 """77 Create a new :class:`ConnectionPool` based on host, port and scheme.78 195 unmodified linesmodified:requests/packages/urllib3/response.py+30 added-4 removed
1 import zlib2 import io3 from socket import timeout as SocketTimeout4 5+from .packages import six6 from ._collections import HTTPHeaderDict7 from .exceptions import ProtocolError, DecodeError, ReadTimeoutError8 from .packages.six import string_types as basestring, binary_type9 from .connection import HTTPException, BaseSSLError10 from .util.response import is_fp_closed11 12 12-13 class DeflateDecoder(object):14 15 def __init__(self):16 self._first_try = True3 unmodified lines20 def __getattr__(self, name):21 return getattr(self._obj, name)22 23 def decompress(self, data):24+ if not data:25+ return data26+27 if not self._first_try:28 return self._obj.decompress(data)29 30 self._data += data7 unmodified lines38 finally:39 self._data = None40 41 42+class GzipDecoder(object):43+44+ def __init__(self):45+ self._obj = zlib.decompressobj(16 + zlib.MAX_WBITS)46+47+ def __getattr__(self, name):48+ return getattr(self._obj, name)49+50+ def decompress(self, data):51+ if not data:52+ return data53+ return self._obj.decompress(data)54+55+56 def _get_decoder(mode):57 if mode == 'gzip':41- return zlib.decompressobj(16 + zlib.MAX_WBITS)58+ return GzipDecoder()59 60 return DeflateDecoder()61 62 155 unmodified lines218 raise ReadTimeoutError(self._pool, None, 'Read timed out.')219 220 except BaseSSLError as e:221 # FIXME: Is there a better way to differentiate between SSLErrors?205- if not 'read operation timed out' in str(e): # Defensive:222+ if 'read operation timed out' not in str(e): # Defensive:223 # This shouldn't happen but just in case we're missing an edge224 # case, let's avoid swallowing SSL errors.225 raise226 59 unmodified lines286 """287 288 headers = HTTPHeaderDict()289 for k, v in r.getheaders():290+ if k.lower() != 'set-cookie':273- headers.add(k, v)291+ headers.add(k, v)292 293+ if six.PY3: # Python 3:294+ cookies = r.msg.get_all('set-cookie') or tuple()295+ else: # Python 2:296+ cookies = r.msg.getheaders('set-cookie')297+298+ for cookie in cookies:299+ headers.add('set-cookie', cookie)300+301 # HTTPResponse objects in Python 3 don't have a .strict attribute302 strict = getattr(r, 'strict', 0)303 return ResponseCls(body=r,304 headers=headers,55 unmodified lines