urllib3 v1.2.2
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 83f4c01 · Browse files · 5 files·+69 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
5 files+69 added−26 removed
- other:+69 added−26 removed
Provenance
- Commit
7cc2d46- Tree
de7888a- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
83f4c01
5 files changed+69 added−26 removed
modified:requests/packages/urllib3/__init__.py+1 added-1 removed
8 unmodified lines9 """10 11 __author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'12 __license__ = 'MIT'13-__version__ = '1.1'13+__version__ = '1.2.2'14 15 16 from .connectionpool import (17 HTTPConnectionPool,31 unmodified linesmodified:requests/packages/urllib3/connectionpool.py+40 added-15 removed
5 unmodified lines6 7 import logging8 import socket9 10+from base64 import b64encode11 from socket import error as SocketError, timeout as SocketTimeout12 13 try:14 from select import poll, POLLIN1 unmodified line16 from select import select17 poll = False18 19 try: # Python 319- from http.client import HTTPConnection, HTTPSConnection, HTTPException20+ from http.client import HTTPConnection, HTTPException21 from http.client import HTTP_PORT, HTTPS_PORT22 except ImportError:22- from httplib import HTTPConnection, HTTPSConnection, HTTPException23+ from httplib import HTTPConnection, HTTPException24 from httplib import HTTP_PORT, HTTPS_PORT25 26 try: # Python 326- from queue import Queue, Empty, Full27+ from queue import LifoQueue, Empty, Full28 except ImportError:28- from Queue import Queue, Empty, Full29+ from Queue import LifoQueue, Empty, Full30 31+32 try: # Compiled with SSL?33+ HTTPSConnection = object34+ BaseSSLError = None35+ ssl = None36+37+ try: # Python 338+ from http.client import HTTPSConnection39+ except ImportError:40+ from httplib import HTTPSConnection41+42 import ssl43 BaseSSLError = ssl.SSLError44+45 except ImportError:34- ssl = None35- BaseSSLError = None46+ pass47 48 49 from .packages.ssl_match_hostname import match_hostname, CertificateError50 from .request import RequestMethods51 from .response import HTTPResponse41-from .exceptions import (SSLError,52+from .exceptions import (53+ EmptyPoolError,54+ HostChangedError,55+ LocationParseError,56 MaxRetryError,57+ SSLError,58 TimeoutError,44- HostChangedError,45- EmptyPoolError,59 )60 61 from .packages.ssl_match_hostname import match_hostname, CertificateError62 from .packages import six52 unmodified lines115 :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`.116 """117 118 scheme = None119+ QueueCls = LifoQueue120 121 def __init__(self, host, port=None):122 self.host = host123 self.port = port45 unmodified lines169 scheme = 'http'170 171 def __init__(self, host, port=None, strict=False, timeout=None, maxsize=1,172 block=False, headers=None):159- self.host = host160- self.port = port173+ super(HTTPConnectionPool, self).__init__(host, port)174+175 self.strict = strict176 self.timeout = timeout163- self.pool = Queue(maxsize)177+ self.pool = self.QueueCls(maxsize)178 self.block = block179 self.headers = headers or {}180 181 # Fill the queue up so that doing get() on it will block properly299 unmodified lines481 self.num_connections += 1482 log.info("Starting new HTTPS connection (%d): %s"483 % (self.num_connections, self.host))484 471- if not ssl:485+ if not ssl: # Platform-specific: Python compiled without +ssl486+ if not HTTPSConnection or HTTPSConnection is object:487+ raise SSLError("Can't connect to HTTPS URL because the SSL "488+ "module is not available.")489+490 return HTTPSConnection(host=self.host, port=self.port)491 492 connection = VerifiedHTTPSConnection(host=self.host, port=self.port)493 connection.set_cert(key_file=self.key_file, cert_file=self.cert_file,49 unmodified lines543 headers['connection'] = 'keep-alive'544 545 if basic_auth:546 headers['authorization'] = 'Basic ' + \529- basic_auth.encode('base64').strip()547+ b64encode(six.b(basic_auth)).decode('utf-8')548 549 return headers550 551 7 unmodified lines559 ('http', 'google.com', None)560 >>> get_host('google.com:80')561 ('http', 'google.com', 80)562 """563+564 # This code is actually similar to urlparse.urlsplit, but much565 # simplified for our needs.566 port = None567 scheme = 'http'568+569 if '://' in url:570 scheme, url = url.split('://', 1)571 if '/' in url:572 url, _path = url.split('/', 1)573 if '@' in url:574 _auth, url = url.split('@', 1)575 if ':' in url:576 url, port = url.split(':', 1)577+578+ if not port.isdigit():579+ raise LocationParseError("Failed to parse: %s")580+581 port = int(port)582+583 return scheme, url, port584 585 586 def connection_from_url(url, **kw):29 unmodified lines616 617 :param conn:618 ``HTTPConnection`` object.619 """595- if not poll:620+ if not poll: # Platform-specific621 return select([conn.sock], [], [], 0.0)[0]622 623 # This version is better on platforms that support it.624 p = poll()5 unmodified linesmodified:requests/packages/urllib3/exceptions.py+17 added-4 removed
2 unmodified lines3 #4 # This module is part of urllib3 and is released under5 # the MIT License: http://www.opensource.org/licenses/mit-license.php6 7+8 ## Base Exceptions9 10 class HTTPError(Exception):11 "Base exception used by this module."15 unmodified lines27 ## Leaf Exceptions28 29 class MaxRetryError(PoolError):30 "Raised when the maximum number of retries is exceeded."31+32 def __init__(self, pool, url):31- PoolError.__init__(self, pool,32- "Max retries exceeded with url: %s" % url)33+ message = "Max retries exceeded with url: %s" % url34+ PoolError.__init__(self, pool, message)35 36 self.url = url37 38 39 class HostChangedError(PoolError):40 "Raised when an existing pool gets a request for a foreign host."41+42 def __init__(self, pool, url, retries=3):40- PoolError.__init__(self, pool,41- "Tried to open a foreign host with url: %s" % url)43+ message = "Tried to open a foreign host with url: %s" % url44+ PoolError.__init__(self, pool, message)45 46 self.url = url47 self.retries = retries48 5 unmodified lines54 55 class EmptyPoolError(PoolError):56 "Raised when a pool runs out of connections and no more are allowed."57 pass58+59+60+class LocationParseError(ValueError, HTTPError):61+ "Raised when get_host or similar fails to parse the URL input."62+63+ def __init__(self, location):64+ message = "Failed to parse: %s" % location65+ super(LocationParseError, self).__init__(self, message)66+67+ self.location = locationmodified:requests/packages/urllib3/poolmanager.py+10 added
115 unmodified lines116 117 def __init__(self, proxy_pool):118 self.proxy_pool = proxy_pool119 120+ def _set_proxy_headers(self, headers=None):121+ headers = headers or {}122+123+ # Same headers are curl passes for --proxy1.0124+ headers['Accept'] = '*/*'125+ headers['Proxy-Connection'] = 'Keep-Alive'126+127+ return headers128+129 def urlopen(self, method, url, **kw):130 "Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute."131 kw['assert_same_host'] = False132+ kw['headers'] = self._set_proxy_headers(kw.get('headers'))133 return self.proxy_pool.urlopen(method, url, **kw)134 135 136 def proxy_from_url(url, **pool_kw):2 unmodified linesmodified:requests/packages/urllib3/response.py+1 added-6 removed
9 unmodified lines10 11 from io import BytesIO12 13 from .exceptions import HTTPError14+from .packages.six import string_types as basestring15 16 16-try:17- basestring = basestring18-except NameError: # Python 319- basestring = (str, bytes)20-21-17 log = logging.getLogger(__name__)18 19 20 def decode_gzip(data):171 unmodified lines