Merge remote-tracking branch 'origin/master'
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 · parents 569b59f, 8f42369 · Browse files · 2 files·+18 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+18 added−7 removed
- other:+18 added−7 removed
Provenance
- Commit
8eb4243- Tree
bd66a2b- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
569b59f- Parent 2
8f42369
2 files changed+18 added−7 removed
modified:requests/adapters.py+15 added-6 removed
23 unmodified lines24 from .cookies import extract_cookies_to_jar25 from .exceptions import ConnectionError, Timeout, SSLError26 from .auth import _basic_auth_str27 28+DEFAULT_POOLBLOCK = False29 DEFAULT_POOLSIZE = 1030 DEFAULT_RETRIES = 031 32 20 unmodified lines53 54 :param pool_connections: The number of urllib3 connection pools to cache.55 :param pool_maxsize: The maximum number of connections to save in the pool.56 :param max_retries: The maximum number of retries each connection should attempt.57+ :param pool_block: Whether the connection pool should block for connections.58 59 Usage::60 61 >>> import requests62 >>> s = requests.Session()63 >>> a = requests.adapters.HTTPAdapter()64 >>> s.mount('http://', a)65 """64- __attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize']66+ __attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize',67+ '_pool_block']68 69 def __init__(self, pool_connections=DEFAULT_POOLSIZE,67- pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES):70+ pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES,71+ pool_block=DEFAULT_POOLBLOCK):72 self.max_retries = max_retries73 self.config = {}74 75 super(HTTPAdapter, self).__init__()76 77 self._pool_connections = pool_connections78 self._pool_maxsize = pool_maxsize79+ self._pool_block = pool_block80 76- self.init_poolmanager(pool_connections, pool_maxsize)81+ self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)82 83 def __getstate__(self):84 return dict((attr, getattr(self, attr, None)) for attr in85 self.__attrs__)1 unmodified line87 def __setstate__(self, state):88 for attr, value in state.items():89 setattr(self, attr, value)90 86- self.init_poolmanager(self._pool_connections, self._pool_maxsize)91+ self.init_poolmanager(self._pool_connections, self._pool_maxsize,92+ block=self._pool_block)93 88- def init_poolmanager(self, connections, maxsize):94+ def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK):95 """Initializes a urllib3 PoolManager. This method should not be called96 from user code, and is only exposed for use when subclassing the97 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.98 99 :param connections: The number of urllib3 connection pools to cache.100 :param maxsize: The maximum number of connections to save in the pool.101+ :param block: Block when no free connections are available.102 """103 # save these values for pickling104 self._pool_connections = connections105 self._pool_maxsize = maxsize106+ self._pool_block = block107 100- self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize)108+ self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,109+ block=block)110 111 def cert_verify(self, conn, url, verify, cert):112 """Verify a SSL certificate. This method should not be called from user113 code, and is only exposed for use when subclassing the229 unmodified linesmodified:requests/sessions.py+3 added-1 removed
109 unmodified lines110 url = '%s:%s' % (parsed_rurl.scheme, url)111 112 # Facilitate non-RFC2616-compliant 'location' headers113 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')114+ # Compliant with RFC3986, we percent encode the url.115 if not urlparse(url).netloc:115- # Compliant with RFC3986, we percent encode the url.116 url = urljoin(resp.url, requote_uri(url))117+ else:118+ url = requote_uri(url)119 120 prepared_request.url = url121 122 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4391 unmodified lines