Skip to content
Myr

Merge pull request #1356 from Zoramite/ConnectionPoolArgs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Adding an argument to the adapter for passing a block argument

authored by Kenneth Reitz · committed by Kenneth Reitz · parents f4e7809, c03e142 · Browse files · 1 file+15 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+15 added−6 removed

  • other:+15 added−6 removed

1 file+15 added−6 removed

modified:requests/adapters.py+15 added-6 removed
23 unmodified lines
24from .cookies import extract_cookies_to_jar25from .exceptions import ConnectionError, Timeout, SSLError26from .auth import _basic_auth_str2728DEFAULT_POOLBLOCK = False29DEFAULT_POOLSIZE = 1030DEFAULT_RETRIES = 03132
20 unmodified lines
5354 :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.5859 Usage::6061 >>> 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']6869 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 = {}7475 super(HTTPAdapter, self).__init__()7677 self._pool_connections = pool_connections78 self._pool_maxsize = pool_maxsize79 self._pool_block = pool_block8076 self.init_poolmanager(pool_connections, pool_maxsize)81 self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)8283 def __getstate__(self):84 return dict((attr, getattr(self, attr, None)) for attr in85 self.__attrs__)
1 unmodified line
87 def __setstate__(self, state):88 for attr, value in state.items():89 setattr(self, attr, value)9086 self.init_poolmanager(self._pool_connections, self._pool_maxsize)91 self.init_poolmanager(self._pool_connections, self._pool_maxsize,92 block=self._pool_block)9388 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>`.9899 :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 = block107100 self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize)108 self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,109 block=block)110111 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 the
229 unmodified lines