Skip to content
Myr

proxies_to_dispatchers -> get_proxy_map (#733)

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

authored by Tom Christie · committed by GitHub · parent 12dd157 · Browse files · 1 file+32 added−58 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+32 added−58 removed

  • other:+32 added−58 removed

1 file+32 added−58 removed

modified:httpx/client.py+32 added-58 removed
145 unmodified lines
146 self.max_redirects = max_redirects147 self.trust_env = trust_env148 self.netrc = NetRCInfo()149150 proxy_map = self.get_proxy_map(proxies, trust_env)151152 self.dispatch = self.init_dispatch(153 verify=verify,154 cert=cert,155 http2=http2,
3 unmodified lines
159 backend=backend,160 trust_env=trust_env,161 uds=uds,162 )163 self.proxies: typing.Dict[str, AsyncDispatcher] = {164 key: self.init_proxy_dispatch(165 proxy,166 verify=verify,167 cert=cert,168 http2=http2,169 pool_limits=pool_limits,170 backend=backend,171 trust_env=trust_env,172 )173 for key, proxy in proxy_map.items()174 }175162 if proxies is None and trust_env:163 proxies = typing.cast(ProxiesTypes, get_environment_proxies())164165 self.proxies: typing.Dict[str, AsyncDispatcher] = self.proxies_to_dispatchers(166 proxies,167 verify=verify,168 cert=cert,169 http2=http2,170 pool_limits=pool_limits,171 backend=backend,172 trust_env=trust_env,173 )174176 def init_dispatch(177 self,178 verify: VerifyTypes = True,179 cert: CertTypes = None,
42 unmodified lines
222 backend=backend,223 trust_env=trust_env,224 )225225 def proxies_to_dispatchers(226 self,227 proxies: typing.Optional[ProxiesTypes],228 verify: VerifyTypes,229 cert: typing.Optional[CertTypes],230 http2: bool,231 pool_limits: PoolLimits,232 backend: typing.Union[str, ConcurrencyBackend],233 trust_env: bool,234 ) -> typing.Dict[str, AsyncDispatcher]:226 def get_proxy_map(227 self, proxies: typing.Optional[ProxiesTypes], trust_env: bool,228 ) -> typing.Dict[str, Proxy]:229 if proxies is None:230 if trust_env:231 return {232 key: Proxy(url=url)233 for key, url in get_environment_proxies().items()234 }235 return {}236 elif isinstance(proxies, (str, URL, Proxy)):237 proxy = Proxy(url=proxies) if isinstance(proxies, (str, URL)) else proxies239 return {240 "all": self.init_proxy_dispatch(241 proxy=proxy,242 verify=verify,243 cert=cert,244 pool_limits=pool_limits,245 backend=backend,246 trust_env=trust_env,247 http2=http2,248 )249 }238 return {"all": proxy}239 elif isinstance(proxies, AsyncDispatcher): # pragma: nocover251 return {"all": proxies}252 # We're supporting this style for now, but we'll want to deprecate it.253 #254 # raise RuntimeError(255 # "Passing a AsyncDispatcher instance to 'proxies=' is no longer256 # supported. Use `httpx.Proxy() instead.`"257 # )240 raise RuntimeError(241 "Passing a dispatcher instance to 'proxies=' is no longer "242 "supported. Use `httpx.Proxy() instead.`"243 )244 else:245 new_proxies = {}246 for key, value in proxies.items():247 if isinstance(value, (str, URL, Proxy)):248 proxy = Proxy(url=value) if isinstance(value, (str, URL)) else value263 new_proxies[str(key)] = self.init_proxy_dispatch(264 proxy=proxy,265 verify=verify,266 cert=cert,267 pool_limits=pool_limits,268 backend=backend,269 trust_env=trust_env,270 http2=http2,271 )249 new_proxies[str(key)] = proxy250 elif isinstance(value, AsyncDispatcher): # pragma: nocover273 new_proxies[str(key)] = value274 # We're supporting this style for now, but we'll want to275 # deprecate it.276 #277 # raise RuntimeError(278 # "Passing a AsyncDispatcher instance to 'proxies=' is "279 # "no longer supported. Use `httpx.Proxy() instead.`"280 # )251 raise RuntimeError(252 "Passing a dispatcher instance to 'proxies=' is "253 "no longer supported. Use `httpx.Proxy() instead.`"254 )255 return new_proxies256257 @property258 def headers(self) -> Headers:
669 unmodified lines