Skip to content
Myr

Add support for SOCKS

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

authored by Cory Benfield · committed by Cory Benfield · parent 396963a · Browse files · 1 file+33 added−10 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+33 added−10 removed

  • other:+33 added−10 removed

1 file+33 added−10 removed

modified:requests/adapters.py+33 added-10 removed
31 unmodified lines
32from .packages.urllib3.exceptions import SSLError as _SSLError33from .packages.urllib3.exceptions import ResponseError34from .cookies import extract_cookies_to_jar35from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,36 ProxyError, RetryError)36 ProxyError, RetryError, InvalidSchema)37from .auth import _basic_auth_str3839try:40 from .packages.urllib3.contrib.socks import SOCKSProxyManager41except ImportError:42 def SOCKSProxyManager(*args, **kwargs):43 raise InvalidSchema("Missing dependencies for SOCKS support.")4445DEFAULT_POOLBLOCK = False46DEFAULT_POOLSIZE = 1047DEFAULT_RETRIES = 048DEFAULT_POOL_TIMEOUT = None
106 unmodified lines
155 :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.156 :returns: ProxyManager157 """158 if not proxy in self.proxy_manager:159 if proxy.lower().startswith('socks'):160 username, password = get_auth_from_url(proxy)161 self.proxy_manager[proxy] = SOCKSProxyManager(162 proxy,163 username=username,164 password=password,165 num_pools=self._pool_connections,166 maxsize=self._pool_maxsize,167 block=self._pool_block,168 **proxy_kwargs169 )170 else:153 proxy_headers = self.proxy_headers(proxy)154 self.proxy_manager[proxy] = proxy_from_url(155 proxy,156 proxy_headers=proxy_headers,157 num_pools=self._pool_connections,158 maxsize=self._pool_maxsize,159 block=self._pool_block,160 **proxy_kwargs)171 proxy_headers = self.proxy_headers(proxy)172 self.proxy_manager[proxy] = proxy_from_url(173 proxy,174 proxy_headers=proxy_headers,175 num_pools=self._pool_connections,176 maxsize=self._pool_maxsize,177 block=self._pool_block,178 **proxy_kwargs)179180 return self.proxy_manager[proxy]181182 def cert_verify(self, conn, url, verify, cert):
118 unmodified lines
301 :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.302 """303 proxy = select_proxy(request.url, proxies)304 scheme = urlparse(request.url).scheme305 proxy_scheme = urlparse(proxy).scheme306307 if proxy and proxy_scheme.lower().startswith('socks'):308 # Socks proxies behave like the proxy isn't there at all.309 url = request.path_url287 if proxy and scheme != 'https':310 elif proxy and scheme != 'https':311 url = urldefragauth(request.url)312 else:313 url = request.path_url314
162 unmodified lines