Factor out HTTPAdapter.proxy_manager_for for #2048
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ben Bass · committed by Ben Bass · parent a7c2184 · Browse files · 1 file·+20 added−11 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+20 added−11 removed
- other:+20 added−11 removed
Provenance
- Commit
f97e787- Tree
d24be92- Author
Ben Bass <benbass@codedstructure.net>- Committer
Ben Bass <benbass@codedstructure.net>- Parent
a7c2184
1 file changed+20 added−11 removed
modified:requests/adapters.py+20 added-11 removed
116 unmodified lines117 118 self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,119 block=block)120 121+ def proxy_manager_for(self, proxy):122+ """Return urllib3 ProxyManager for the given proxy. This method should123+ not be called from user code, and is only exposed for use when124+ subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.125+126+ :param proxy: The proxy to return a urllib3 ProxyManager for.127+ """128+ if not proxy in self.proxy_manager:129+ proxy_headers = self.proxy_headers(proxy)130+ self.proxy_manager[proxy] = proxy_from_url(131+ proxy,132+ proxy_headers=proxy_headers,133+ num_pools=self._pool_connections,134+ maxsize=self._pool_maxsize,135+ block=self._pool_block)136+137+ return self.proxy_manager[proxy]138+139 def cert_verify(self, conn, url, verify, cert):140 """Verify a SSL certificate. This method should not be called from user141 code, and is only exposed for use when subclassing the142 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.78 unmodified lines221 proxy = proxies.get(urlparse(url.lower()).scheme)222 223 if proxy:224 proxy = prepend_scheme_if_needed(proxy, 'http')207- proxy_headers = self.proxy_headers(proxy)208-209- 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)216-217- conn = self.proxy_manager[proxy].connection_from_url(url)225+ proxy_manager = self.proxy_manager_for(proxy)226+ conn = proxy_manager.connection_from_url(url)227 else:228 # Only scheme should be lower case229 parsed = urlparse(url)230 url = parsed.geturl()167 unmodified lines