Update urllib3 to df4ec5cce1
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ian Cordasco · committed by Ian Cordasco · parent 2bc7762 · Browse files · 7 files·+97 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+97 added−26 removed
- other:+97 added−26 removed
Provenance
- Commit
f54a4e3- Tree
9b7feed- Author
Ian Cordasco <graffatcolmingov@gmail.com>- Committer
Ian Cordasco <graffatcolmingov@gmail.com>- Parent
2bc7762
7 files changed+97 added−26 removed
modified:requests/packages/urllib3/contrib/pyopenssl.py+16 added-2 removed
27 unmodified lines28 Now you can use :mod:`urllib3` as you normally would, and it will support SNI29 when the required modules are installed.30 31 Activating this module also has the positive side effect of disabling SSL/TLS32-encryption in Python 2 (see `CRIME attack`_).32+compression in Python 2 (see `CRIME attack`_).33 34 If you want to configure the default list of supported cipher suites, you can35 set the ``urllib3.contrib.pyopenssl.DEFAULT_SSL_CIPHER_LIST`` variable.36 161 unmodified lines198 199 def settimeout(self, timeout):200 return self.socket.settimeout(timeout)201 202+ def _send_until_done(self, data):203+ while True:204+ try:205+ return self.connection.send(data)206+ except OpenSSL.SSL.WantWriteError:207+ _, wlist, _ = select.select([], [self.socket], [],208+ self.socket.gettimeout())209+ if not wlist:210+ raise timeout()211+ continue212+213 def sendall(self, data):203- return self.connection.sendall(data)214+ while len(data):215+ sent = self._send_until_done(data)216+ data = data[sent:]217 218 def close(self):219 if self._makefile_refs < 1:220 return self.connection.shutdown()39 unmodified lines260 ca_certs=None, server_hostname=None,261 ssl_version=None):262 ctx = OpenSSL.SSL.Context(_openssl_versions[ssl_version])263 if certfile:264+ keyfile = keyfile or certfile # Match behaviour of the normal python ssl library265 ctx.use_certificate_file(certfile)266 if keyfile:267 ctx.use_privatekey_file(keyfile)268 if cert_reqs != ssl.CERT_NONE:30 unmodified linesmodified:requests/packages/urllib3/util/retry.py+15 added-9 removed
1 import time2 import logging3 4 from ..exceptions import (5- ProtocolError,5 ConnectTimeoutError,7- ReadTimeoutError,6 MaxRetryError,7+ ProtocolError,8+ ReadTimeoutError,9+ ResponseError,10 )11 from ..packages import six12 13 22 unmodified lines36 37 Errors will be wrapped in :class:`~urllib3.exceptions.MaxRetryError` unless38 retries are disabled, in which case the causing exception will be raised.39 39-40 :param int total:41 Total number of retries to allow. Takes precedence over other counts.42 43 Set to ``None`` to remove this constraint and fall back on other139 unmodified lines183 """184 return isinstance(err, ConnectTimeoutError)185 186 def _is_read_error(self, err):187- """ Errors that occur after the request has been started, so we can't188- assume that the server did not process any of it.187+ """ Errors that occur after the request has been started, so we should188+ assume that the server began processing it.189 """190 return isinstance(err, (ReadTimeoutError, ProtocolError))191 192 def is_forced_retry(self, method, status_code):4 unmodified lines197 198 return self.status_forcelist and status_code in self.status_forcelist199 200 def is_exhausted(self):201- """ Are we out of retries?202- """201+ """ Are we out of retries? """202 retry_counts = (self.total, self.connect, self.read, self.redirect)203 retry_counts = list(filter(None, retry_counts))204 if not retry_counts:205 return False22 unmodified lines228 _observed_errors = self._observed_errors229 connect = self.connect230 read = self.read231 redirect = self.redirect232+ cause = 'unknown'233 234 if error and self._is_connection_error(error):235 # Connect retry?236 if connect is False:13 unmodified lines250 elif response and response.get_redirect_location():251 # Redirect retry?252 if redirect is not None:253 redirect -= 1254+ cause = 'too many redirects'255 256 else:256- # FIXME: Nothing changed, scenario doesn't make sense.257+ # Incrementing because of a server error like a 500 in258+ # status_forcelist and a the given method is in the whitelist259 _observed_errors += 1260+ cause = ResponseError.GENERIC_ERROR261+ if response and response.status:262+ cause = ResponseError.SPECIFIC_ERROR.format(263+ status_code=response.status)264 265 new_retry = self.new(266 total=total,267 connect=connect, read=read, redirect=redirect,268 _observed_errors=_observed_errors)269 270 if new_retry.is_exhausted():265- raise MaxRetryError(_pool, url, error)271+ raise MaxRetryError(_pool, url, error or ResponseError(cause))272 273 log.debug("Incremented Retry for (url='%s'): %r" % (url, new_retry))274 275 return new_retry10 unmodified linesmodified:requests/packages/urllib3/util/url.py+43 added-2 removed
38 unmodified lines39 if self.port:40 return '%s:%d' % (self.host, self.port)41 return self.host42 43+ @property44+ def url(self):45+ """46+ Convert self into a url47 48+ This function should more or less round-trip with :func:`.parse_url`. The49+ returned url may not be exactly the same as the url inputted to50+ :func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls51+ with a blank port will have : removed).52+53+ Example: ::54+55+ >>> U = parse_url('http://google.com/mail/')56+ >>> U.url57+ 'http://google.com/mail/'58+ >>> Url('http', 'username:password', 'host.com', 80,59+ ... '/path', 'query', 'fragment').url60+ 'http://username:password@host.com:80/path?query#fragment'61+ """62+ scheme, auth, host, port, path, query, fragment = self63+ url = ''64+65+ # We use "is not None" we want things to happen with empty strings (or 0 port)66+ if scheme is not None:67+ url += scheme + '://'68+ if auth is not None:69+ url += auth + '@'70+ if host is not None:71+ url += host72+ if port is not None:73+ url += ':' + str(port)74+ if path is not None:75+ url += path76+ if query is not None:77+ url += '?' + query78+ if fragment is not None:79+ url += '#' + fragment80+81+ return url82+83+ def __str__(self):84+ return self.url85+86 def split_first(s, delims):87 """88 Given a string and an iterable of delimiters, split on the first found89 delimiter. Return two split parts and the matched delimiter.35 unmodified lines125 126 Example::127 128 >>> parse_url('http://google.com/mail/')87- Url(scheme='http', host='google.com', port=None, path='/', ...)129+ Url(scheme='http', host='google.com', port=None, path='/mail/', ...)130 >>> parse_url('google.com:80')131 Url(scheme=None, host='google.com', port=80, path=None, ...)132 >>> parse_url('/foo?bar')133 Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...)69 unmodified lines203 path, query = path.split('?', 1)204 205 return Url(scheme, auth, host, port, path, query, fragment)206 165-207 def get_host(url):208 """209 Deprecated. Use :func:`.parse_url` instead.210 """2 unmodified linesmodified:requests/packages/urllib3/_collections.py+3 added-4 removed
12 unmodified lines13 try: # Python 2.7+14 from collections import OrderedDict15 except ImportError:16 from .packages.ordered_dict import OrderedDict17-from .packages.six import itervalues17+from .packages.six import iterkeys, itervalues18 19 20 __all__ = ['RecentlyUsedContainer', 'HTTPHeaderDict']21 62 unmodified lines84 85 def clear(self):86 with self.lock:87 # Copy pointers to all values, then wipe the mapping88- # under Python 2, this copies the list of values twice :-|89- values = list(self._container.values())88+ values = list(itervalues(self._container))89 self._container.clear()90 91 if self.dispose_func:92 for value in values:93 self.dispose_func(value)94 95 def keys(self):96 with self.lock:98- return self._container.keys()97+ return list(iterkeys(self._container))98 99 100 class HTTPHeaderDict(MutableMapping):101 """97 unmodified linesmodified:requests/packages/urllib3/connection.py+10 added-2 removed
1 unmodified line2 import sys3 import socket4 from socket import timeout as SocketTimeout5 import warnings6+from .packages import six7 8 try: # Python 39 from http.client import HTTPConnection as _HTTPConnection, HTTPException10 except ImportError:15 unmodified lines26 class BaseSSLError(BaseException):27 pass28 29 30+try: # Python 3:31+ # Not a no-op, we're adding this to the namespace so it can be imported.32+ ConnectionError = ConnectionError33+except NameError: # Python 2:34+ class ConnectionError(Exception):35+ pass36+37+38 from .exceptions import (39 ConnectTimeoutError,40 SystemTimeWarning,41 )42 from .packages.ssl_match_hostname import match_hostname34-from .packages import six43 44 from .util.ssl_ import (45 resolve_cert_reqs,46 resolve_ssl_version,47 ssl_wrap_socket,48 assert_fingerprint,49 )50 51+52 from .util import connection53 45-54 port_by_scheme = {55 'http': 80,56 'https': 443,57 }197 unmodified linesmodified:requests/packages/urllib3/connectionpool.py+2 added-2 removed
30 unmodified lines31 from .connection import (32 port_by_scheme,33 DummyConnection,34 HTTPConnection, HTTPSConnection, VerifiedHTTPSConnection,35- HTTPException, BaseSSLError,35+ HTTPException, BaseSSLError, ConnectionError36 )37 from .request import RequestMethods38 from .response import HTTPResponse39 501 unmodified lines541 # close it externally in case of exception.542 release_conn = True543 raise SSLError(e)544 545- except (TimeoutError, HTTPException, SocketError) as e:545+ except (TimeoutError, HTTPException, SocketError, ConnectionError) as e:546 if conn:547 # Discard the connection for these exceptions. It will be548 # be replaced during the next _get_conn() call.549 conn.close()208 unmodified linesmodified:requests/packages/urllib3/exceptions.py+8 added-5 removed
70 unmodified lines71 72 def __init__(self, pool, url, reason=None):73 self.reason = reason74 75- message = "Max retries exceeded with url: %s" % url76- if reason:77- message += " (Caused by %r)" % reason78- else:79- message += " (Caused by redirect)"75+ message = "Max retries exceeded with url: %s (Caused by %r)" % (76+ url, reason)77 78 RequestError.__init__(self, pool, url, message)79 80 56 unmodified lines137 138 self.location = location139 140 141+class ResponseError(HTTPError):142+ "Used as a container for an error reason supplied in a MaxRetryError."143+ GENERIC_ERROR = 'too many error responses'144+ SPECIFIC_ERROR = 'too many {status_code} error responses'145+146+147 class SecurityWarning(HTTPWarning):148 "Warned when perfoming security reducing actions"149 pass150 9 unmodified lines