From: Kenneth Reitz Date: Mon, 25 Jun 2012 16:35:39 +0000 (-0400) Subject: update urllib3 X-Git-Tag: v0.13.2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f0ac668da796b04df9901db58f5d4215be308dd;p=services%2Fpython-requests.git update urllib3 --- diff --git a/requests/packages/urllib3/__init__.py b/requests/packages/urllib3/__init__.py index 81e76f5..55de87e 100644 --- a/requests/packages/urllib3/__init__.py +++ b/requests/packages/urllib3/__init__.py @@ -28,7 +28,7 @@ from .util import make_headers, get_host # Set default logging handler to avoid "No handler found" warnings. import logging -try: +try: # Python 2.7+ from logging import NullHandler except ImportError: class NullHandler(logging.Handler): @@ -37,6 +37,22 @@ except ImportError: logging.getLogger(__name__).addHandler(NullHandler()) +def add_stderr_logger(level=logging.DEBUG): + """ + Helper for quickly adding a StreamHandler to the logger. Useful for + debugging. + + Returns the handler after adding it. + """ + # This method needs to be in this __init__.py to get the __name__ correct + # even if urllib3 is vendored within another package. + logger = logging.getLogger(__name__) + handler = logging.StreamHandler() + handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) + logger.addHandler(handler) + logger.setLevel(level) + logger.debug('Added an stderr logging handler to logger: %s' % __name__) + return handler + # ... Clean up. -del logging del NullHandler diff --git a/requests/packages/urllib3/connectionpool.py b/requests/packages/urllib3/connectionpool.py index f233341..071fd7e 100644 --- a/requests/packages/urllib3/connectionpool.py +++ b/requests/packages/urllib3/connectionpool.py @@ -264,7 +264,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods): httplib_response = conn.getresponse() # AppEngine doesn't have a version attr. - http_version = getattr(conn, '_http_vsn_str', 'HTTP/?'), + http_version = getattr(conn, '_http_vsn_str', 'HTTP/?') log.debug("\"%s %s %s\" %s %s" % (method, url, http_version, httplib_response.status, httplib_response.length)) @@ -324,8 +324,8 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods): Number of retries to allow before raising a MaxRetryError exception. :param redirect: - Automatically handle redirects (status codes 301, 302, 303, 307), - each redirect counts as a retry. + If True, automatically handle redirects (status codes 301, 302, + 303, 307). Each redirect counts as a retry. :param assert_same_host: If ``True``, will make sure that the host of the pool requests is diff --git a/requests/packages/urllib3/util.py b/requests/packages/urllib3/util.py index 486e8fa..9669ce9 100644 --- a/requests/packages/urllib3/util.py +++ b/requests/packages/urllib3/util.py @@ -110,30 +110,47 @@ def get_host(url): ('http', 'google.com', 80) """ - # This code is actually similar to urlparse.urlsplit, but much - # simplified for our needs. - port = None + # While this code has overlap with stdlib's urlparse, it is much + # simplified for our needs and less annoying. + # Additionally, this imeplementations does silly things to be optimal + # on CPython. + scheme = 'http' + host = None + port = None + # Scheme if '://' in url: scheme, url = url.split('://', 1) # Find the earliest Authority Terminator - # http://tools.ietf.org/html/rfc3986#section-3.2 + # (http://tools.ietf.org/html/rfc3986#section-3.2) url, _path = split_first(url, ['/', '?', '#']) + # Auth if '@' in url: _auth, url = url.split('@', 1) + + # IPv6 + if url and url[0] == '[': + host, url = url[1:].split(']', 1) + + # Port if ':' in url: - url, port = url.split(':', 1) + _host, port = url.split(':', 1) + + if not host: + host = _host if not port.isdigit(): raise LocationParseError("Failed to parse: %s" % url) port = int(port) - return scheme, url, port + elif not host: + host = url + return scheme, host, port def is_connection_dropped(conn):