Skip to content
Myr

Merge pull request #2049 from codedstructure/adapter-proxy_manager_for

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

Separated out proxy_manager_for to fix #2048

authored by Kenneth Reitz · committed by Kenneth Reitz · parents fcb735f, 046302c · Browse files · 2 files+34 added−16 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+34 added−16 removed

  • other:+34 added−16 removed

2 files+34 added−16 removed

modified:requests/adapters.py+32 added-15 removed
99 unmodified lines
100101 self.init_poolmanager(self._pool_connections, self._pool_maxsize,102 block=self._pool_block)103104 def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK):105 """Initializes a urllib3 PoolManager. This method should not be called106 from user code, and is only exposed for use when subclassing the104 def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs):105 """Initializes a urllib3 PoolManager.106107 This method should not be called from user code, and is only108 exposed for use when subclassing the109 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.110111 :param connections: The number of urllib3 connection pools to cache.112 :param maxsize: The maximum number of connections to save in the pool.113 :param block: Block when no free connections are available.114 :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.115 """116 # save these values for pickling117 self._pool_connections = connections118 self._pool_maxsize = maxsize119 self._pool_block = block120121 self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,119 block=block)122 block=block, **pool_kwargs)123124 def proxy_manager_for(self, proxy, **proxy_kwargs):125 """Return urllib3 ProxyManager for the given proxy.126127 This method should not be called from user code, and is only128 exposed for use when subclassing the129 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.130131 :param proxy: The proxy to return a urllib3 ProxyManager for.132 :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.133 :returns: ProxyManager134 """135 if not proxy in self.proxy_manager:136 proxy_headers = self.proxy_headers(proxy)137 self.proxy_manager[proxy] = proxy_from_url(138 proxy,139 proxy_headers=proxy_headers,140 num_pools=self._pool_connections,141 maxsize=self._pool_maxsize,142 block=self._pool_block,143 **proxy_kwargs)144145 return self.proxy_manager[proxy]146147 def cert_verify(self, conn, url, verify, cert):148 """Verify a SSL certificate. This method should not be called from user149 code, and is only exposed for use when subclassing the150 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
78 unmodified lines
229 proxy = proxies.get(urlparse(url.lower()).scheme)230231 if proxy:232 proxy = prepend_scheme_if_needed(proxy, 'http')207 proxy_headers = self.proxy_headers(proxy)208209 if not proxy in self.proxy_manager:210 self.proxy_manager[proxy] = proxy_from_url(211 proxy,212 proxy_headers=proxy_headers,213 num_pools=self._pool_connections,214 maxsize=self._pool_maxsize,215 block=self._pool_block)216217 conn = self.proxy_manager[proxy].connection_from_url(url)233 proxy_manager = self.proxy_manager_for(proxy)234 conn = proxy_manager.connection_from_url(url)235 else:236 # Only scheme should be lower case237 parsed = urlparse(url)238 url = parsed.geturl()
167 unmodified lines
modified:AUTHORS.rst+2 added-1 removed
149 unmodified lines
150- Pengfei.X <pengphy@gmail.com>151- Kamil Madac <kamil.madac@gmail.com>152- Michael Becker <mike@beckerfuffle.com> @beckerfuffle153- Erik Wickstrom <erik@erikwickstrom.com> @erikwickstrom154- Константин Подшумок @podshumok154- Константин Подшумок @podshumok155- Ben Bass @codedstructure