update urllib3
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 64da351 · Browse files · 3 files·+44 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
3 files+44 added−11 removed
- other:+44 added−11 removed
Provenance
- Commit
8f0ac66- Tree
6dcdf1c- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
64da351
3 files changed+44 added−11 removed
modified:requests/packages/urllib3/__init__.py+18 added-2 removed
26 unmodified lines27 28 29 # Set default logging handler to avoid "No handler found" warnings.30 import logging31-try:31+try: # Python 2.7+32 from logging import NullHandler33 except ImportError:34 class NullHandler(logging.Handler):35 def emit(self, record):36 pass37 38 logging.getLogger(__name__).addHandler(NullHandler())39 40+def add_stderr_logger(level=logging.DEBUG):41+ """42+ Helper for quickly adding a StreamHandler to the logger. Useful for43+ debugging.44+45+ Returns the handler after adding it.46+ """47+ # This method needs to be in this __init__.py to get the __name__ correct48+ # even if urllib3 is vendored within another package.49+ logger = logging.getLogger(__name__)50+ handler = logging.StreamHandler()51+ handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))52+ logger.addHandler(handler)53+ logger.setLevel(level)54+ logger.debug('Added an stderr logging handler to logger: %s' % __name__)55+ return handler56+57 # ... Clean up.41-del logging58 del NullHandlermodified:requests/packages/urllib3/connectionpool.py+3 added-3 removed
262 unmodified lines263 except TypeError: # Python 2.6 and older264 httplib_response = conn.getresponse()265 266 # AppEngine doesn't have a version attr.267- http_version = getattr(conn, '_http_vsn_str', 'HTTP/?'),267+ http_version = getattr(conn, '_http_vsn_str', 'HTTP/?')268 log.debug("\"%s %s %s\" %s %s" % (method, url, http_version,269 httplib_response.status,270 httplib_response.length))271 51 unmodified lines323 :param retries:324 Number of retries to allow before raising a MaxRetryError exception.325 326 :param redirect:327- Automatically handle redirects (status codes 301, 302, 303, 307),328- each redirect counts as a retry.327+ If True, automatically handle redirects (status codes 301, 302,328+ 303, 307). Each redirect counts as a retry.329 330 :param assert_same_host:331 If ``True``, will make sure that the host of the pool requests is332 consistent else will raise HostChangedError. When False, you can193 unmodified linesmodified:requests/packages/urllib3/util.py+23 added-6 removed
108 unmodified lines109 >>> get_host('google.com:80')110 ('http', 'google.com', 80)111 """112 113- # This code is actually similar to urlparse.urlsplit, but much114- # simplified for our needs.115- port = None113+ # While this code has overlap with stdlib's urlparse, it is much114+ # simplified for our needs and less annoying.115+ # Additionally, this imeplementations does silly things to be optimal116+ # on CPython.117+118 scheme = 'http'119+ host = None120+ port = None121 122+ # Scheme123 if '://' in url:124 scheme, url = url.split('://', 1)125 126 # Find the earliest Authority Terminator122- # http://tools.ietf.org/html/rfc3986#section-3.2127+ # (http://tools.ietf.org/html/rfc3986#section-3.2)128 url, _path = split_first(url, ['/', '?', '#'])129 130+ # Auth131 if '@' in url:132 _auth, url = url.split('@', 1)133+134+ # IPv6135+ if url and url[0] == '[':136+ host, url = url[1:].split(']', 1)137+138+ # Port139 if ':' in url:128- url, port = url.split(':', 1)140+ _host, port = url.split(':', 1)141 142+ if not host:143+ host = _host144+145 if not port.isdigit():146 raise LocationParseError("Failed to parse: %s" % url)147 148 port = int(port)149 135- return scheme, url, port150+ elif not host:151+ host = url152 153+ return scheme, host, port154 155 156 def is_connection_dropped(conn):157 """25 unmodified lines