Skip to content
Myr

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

7 files+97 added−26 removed

modified:requests/packages/urllib3/contrib/pyopenssl.py+16 added-2 removed
27 unmodified lines
28Now you can use :mod:`urllib3` as you normally would, and it will support SNI29when the required modules are installed.3031Activating this module also has the positive side effect of disabling SSL/TLS32encryption in Python 2 (see `CRIME attack`_).32compression in Python 2 (see `CRIME attack`_).3334If you want to configure the default list of supported cipher suites, you can35set the ``urllib3.contrib.pyopenssl.DEFAULT_SSL_CIPHER_LIST`` variable.36
161 unmodified lines
198199 def settimeout(self, timeout):200 return self.socket.settimeout(timeout)201202 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 continue212213 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:]217218 def close(self):219 if self._makefile_refs < 1:220 return self.connection.shutdown()
39 unmodified lines
260 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 lines
modified:requests/packages/urllib3/util/retry.py+15 added-9 removed
1import time2import logging34from ..exceptions import (5 ProtocolError,5 ConnectTimeoutError,7 ReadTimeoutError,6 MaxRetryError,7 ProtocolError,8 ReadTimeoutError,9 ResponseError,10)11from ..packages import six1213
22 unmodified lines
3637 Errors will be wrapped in :class:`~urllib3.exceptions.MaxRetryError` unless38 retries are disabled, in which case the causing exception will be raised.393940 :param int total:41 Total number of retries to allow. Takes precedence over other counts.4243 Set to ``None`` to remove this constraint and fall back on other
139 unmodified lines
183 """184 return isinstance(err, ConnectTimeoutError)185186 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))191192 def is_forced_retry(self, method, status_code):
4 unmodified lines
197198 return self.status_forcelist and status_code in self.status_forcelist199200 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 False
22 unmodified lines
228 _observed_errors = self._observed_errors229 connect = self.connect230 read = self.read231 redirect = self.redirect232 cause = 'unknown'233234 if error and self._is_connection_error(error):235 # Connect retry?236 if connect is False:
13 unmodified lines
250 elif response and response.get_redirect_location():251 # Redirect retry?252 if redirect is not None:253 redirect -= 1254 cause = 'too many redirects'255256 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)264265 new_retry = self.new(266 total=total,267 connect=connect, read=read, redirect=redirect,268 _observed_errors=_observed_errors)269270 if new_retry.is_exhausted():265 raise MaxRetryError(_pool, url, error)271 raise MaxRetryError(_pool, url, error or ResponseError(cause))272273 log.debug("Incremented Retry for (url='%s'): %r" % (url, new_retry))274275 return new_retry
10 unmodified lines
modified:requests/packages/urllib3/util/url.py+43 added-2 removed
38 unmodified lines
39 if self.port:40 return '%s:%d' % (self.host, self.port)41 return self.host4243 @property44 def url(self):45 """46 Convert self into a url4748 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).5253 Example: ::5455 >>> 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 = ''6465 # 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 += '#' + fragment8081 return url8283 def __str__(self):84 return self.url8586def 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 lines
125126 Example::127128 >>> 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 lines
203 path, query = path.split('?', 1)204205 return Url(scheme, auth, host, port, path, query, fragment)206165207def get_host(url):208 """209 Deprecated. Use :func:`.parse_url` instead.210 """
2 unmodified lines
modified:requests/packages/urllib3/_collections.py+3 added-4 removed
12 unmodified lines
13try: # Python 2.7+14 from collections import OrderedDict15except ImportError:16 from .packages.ordered_dict import OrderedDict17from .packages.six import itervalues17from .packages.six import iterkeys, itervalues181920__all__ = ['RecentlyUsedContainer', 'HTTPHeaderDict']21
62 unmodified lines
8485 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()9091 if self.dispose_func:92 for value in values:93 self.dispose_func(value)9495 def keys(self):96 with self.lock:98 return self._container.keys()97 return list(iterkeys(self._container))9899100class HTTPHeaderDict(MutableMapping):101 """
97 unmodified lines
modified:requests/packages/urllib3/connection.py+10 added-2 removed
1 unmodified line
2import sys3import socket4from socket import timeout as SocketTimeout5import warnings6from .packages import six78try: # Python 39 from http.client import HTTPConnection as _HTTPConnection, HTTPException10except ImportError:
15 unmodified lines
26 class BaseSSLError(BaseException):27 pass282930try: # Python 3:31 # Not a no-op, we're adding this to the namespace so it can be imported.32 ConnectionError = ConnectionError33except NameError: # Python 2:34 class ConnectionError(Exception):35 pass363738from .exceptions import (39 ConnectTimeoutError,40 SystemTimeWarning,41)42from .packages.ssl_match_hostname import match_hostname34from .packages import six4344from .util.ssl_ import (45 resolve_cert_reqs,46 resolve_ssl_version,47 ssl_wrap_socket,48 assert_fingerprint,49)505152from .util import connection534554port_by_scheme = {55 'http': 80,56 'https': 443,57}
197 unmodified lines
modified:requests/packages/urllib3/connectionpool.py+2 added-2 removed
30 unmodified lines
31from .connection import (32 port_by_scheme,33 DummyConnection,34 HTTPConnection, HTTPSConnection, VerifiedHTTPSConnection,35 HTTPException, BaseSSLError,35 HTTPException, BaseSSLError, ConnectionError36)37from .request import RequestMethods38from .response import HTTPResponse39
501 unmodified lines
541 # close it externally in case of exception.542 release_conn = True543 raise SSLError(e)544545 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 lines
modified:requests/packages/urllib3/exceptions.py+8 added-5 removed
70 unmodified lines
7172 def __init__(self, pool, url, reason=None):73 self.reason = reason7475 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)7778 RequestError.__init__(self, pool, url, message)7980
56 unmodified lines
137138 self.location = location139140141class 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'145146147class SecurityWarning(HTTPWarning):148 "Warned when perfoming security reducing actions"149 pass150
9 unmodified lines