Skip to content
Myr

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

5 files+69 added−26 removed

modified:requests/packages/urllib3/__init__.py+1 added-1 removed
8 unmodified lines
9"""1011__author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'12__license__ = 'MIT'13__version__ = '1.1'13__version__ = '1.2.2'141516from .connectionpool import (17 HTTPConnectionPool,
31 unmodified lines
modified:requests/packages/urllib3/connectionpool.py+40 added-15 removed
5 unmodified lines
67import logging8import socket910from base64 import b64encode11from socket import error as SocketError, timeout as SocketTimeout1213try:14 from select import poll, POLLIN
1 unmodified line
16 from select import select17 poll = False1819try: # Python 319 from http.client import HTTPConnection, HTTPSConnection, HTTPException20 from http.client import HTTPConnection, HTTPException21 from http.client import HTTP_PORT, HTTPS_PORT22except ImportError:22 from httplib import HTTPConnection, HTTPSConnection, HTTPException23 from httplib import HTTPConnection, HTTPException24 from httplib import HTTP_PORT, HTTPS_PORT2526try: # Python 326 from queue import Queue, Empty, Full27 from queue import LifoQueue, Empty, Full28except ImportError:28 from Queue import Queue, Empty, Full29 from Queue import LifoQueue, Empty, Full303132try: # Compiled with SSL?33 HTTPSConnection = object34 BaseSSLError = None35 ssl = None3637 try: # Python 338 from http.client import HTTPSConnection39 except ImportError:40 from httplib import HTTPSConnection4142 import ssl43 BaseSSLError = ssl.SSLError4445except ImportError:34 ssl = None35 BaseSSLError = None46 pass474849from .packages.ssl_match_hostname import match_hostname, CertificateError50from .request import RequestMethods51from .response import HTTPResponse41from .exceptions import (SSLError,52from .exceptions import (53 EmptyPoolError,54 HostChangedError,55 LocationParseError,56 MaxRetryError,57 SSLError,58 TimeoutError,44 HostChangedError,45 EmptyPoolError,59)6061from .packages.ssl_match_hostname import match_hostname, CertificateError62from .packages import six
52 unmodified lines
115 :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`.116 """117118 scheme = None119 QueueCls = LifoQueue120121 def __init__(self, host, port=None):122 self.host = host123 self.port = port
45 unmodified lines
169 scheme = 'http'170171 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)174175 self.strict = strict176 self.timeout = timeout163 self.pool = Queue(maxsize)177 self.pool = self.QueueCls(maxsize)178 self.block = block179 self.headers = headers or {}180181 # Fill the queue up so that doing get() on it will block properly
299 unmodified lines
481 self.num_connections += 1482 log.info("Starting new HTTPS connection (%d): %s"483 % (self.num_connections, self.host))484471 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.")489490 return HTTPSConnection(host=self.host, port=self.port)491492 connection = VerifiedHTTPSConnection(host=self.host, port=self.port)493 connection.set_cert(key_file=self.key_file, cert_file=self.cert_file,
49 unmodified lines
543 headers['connection'] = 'keep-alive'544545 if basic_auth:546 headers['authorization'] = 'Basic ' + \529 basic_auth.encode('base64').strip()547 b64encode(six.b(basic_auth)).decode('utf-8')548549 return headers550551
7 unmodified lines
559 ('http', 'google.com', None)560 >>> get_host('google.com:80')561 ('http', 'google.com', 80)562 """563564 # This code is actually similar to urlparse.urlsplit, but much565 # simplified for our needs.566 port = None567 scheme = 'http'568569 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)577578 if not port.isdigit():579 raise LocationParseError("Failed to parse: %s")580581 port = int(port)582583 return scheme, url, port584585586def connection_from_url(url, **kw):
29 unmodified lines
616617 :param conn:618 ``HTTPConnection`` object.619 """595 if not poll:620 if not poll: # Platform-specific621 return select([conn.sock], [], [], 0.0)[0]622623 # This version is better on platforms that support it.624 p = poll()
5 unmodified lines
modified:requests/packages/urllib3/exceptions.py+17 added-4 removed
2 unmodified lines
3#4# This module is part of urllib3 and is released under5# the MIT License: http://www.opensource.org/licenses/mit-license.php678## Base Exceptions910class HTTPError(Exception):11 "Base exception used by this module."
15 unmodified lines
27## Leaf Exceptions2829class MaxRetryError(PoolError):30 "Raised when the maximum number of retries is exceeded."3132 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)3536 self.url = url373839class HostChangedError(PoolError):40 "Raised when an existing pool gets a request for a foreign host."4142 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)4546 self.url = url47 self.retries = retries48
5 unmodified lines
5455class EmptyPoolError(PoolError):56 "Raised when a pool runs out of connections and no more are allowed."57 pass585960class LocationParseError(ValueError, HTTPError):61 "Raised when get_host or similar fails to parse the URL input."6263 def __init__(self, location):64 message = "Failed to parse: %s" % location65 super(LocationParseError, self).__init__(self, message)6667 self.location = location
modified:requests/packages/urllib3/poolmanager.py+10 added
115 unmodified lines
116117 def __init__(self, proxy_pool):118 self.proxy_pool = proxy_pool119120 def _set_proxy_headers(self, headers=None):121 headers = headers or {}122123 # Same headers are curl passes for --proxy1.0124 headers['Accept'] = '*/*'125 headers['Proxy-Connection'] = 'Keep-Alive'126127 return headers128129 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)134135136def proxy_from_url(url, **pool_kw):
2 unmodified lines
modified:requests/packages/urllib3/response.py+1 added-6 removed
9 unmodified lines
1011from io import BytesIO1213from .exceptions import HTTPError14from .packages.six import string_types as basestring151616try:17 basestring = basestring18except NameError: # Python 319 basestring = (str, bytes)202117log = logging.getLogger(__name__)181920def decode_gzip(data):
171 unmodified lines