Environment variables
proxylib.env
Proxy configuration from *_proxy environment variables.
:class:EnvProxyConfig reads a proxy per scheme plus bypass rules from an
environment mapping -- the process environment by default -- the way curl and
Go's httpproxy do.
__all__ = ('EnvProxyConfig',)
module-attribute
EnvProxyConfig(env=None, *, proxies=None, no_proxy=None)
A proxy map from *_proxy environment variables.
env is the environment to read: None (the default) reads
os.environ, any other mapping is read instead ({} reads nothing).
It supplies every <scheme>_proxy, all_proxy and no_proxy; a
lowercase name wins over its uppercase form. Inside a CGI request
(REQUEST_METHOD set) an uppercase HTTP_PROXY is ignored, since a
client's Proxy: header can set it (httpoxy); with os.environ on
Windows, whose names are case-insensitive, http_proxy is then ignored
too.
proxies and no_proxy, when given, are applied over what env
supplied. proxies maps a URL scheme, or "all", to a proxy: a
Proxy, a proxy URL (scheme-less means http), or a PAC location (a
file: URL, or an http(s) URL with a path), which is loaded on the
first lookup that needs it. no_proxy is :class:BypassRules or
NO_PROXY text, and replaces the environment's.
A lookup answers DIRECT for a bypassed URL, else the proxy for the URL's
scheme (ws/wss fall back to http/https), else the "all"
proxy; with none of those it raises KeyError (no opinion), since the
environment cannot say "DIRECT".
Source code in src/proxylib/env.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
__slots__ = ('proxies', 'no_proxy', '_maps')
class-attribute
instance-attribute
no_proxy = no_proxy if isinstance(no_proxy, BypassRules) else BypassRules.parse(no_proxy)
instance-attribute
proxies = {k: v for k, v in merged.items() if v}
instance-attribute
__getitem__(url)
Source code in src/proxylib/env.py
80 81 82 83 84 85 86 87 | |
__repr__()
Source code in src/proxylib/env.py
71 72 73 | |
close()
End the helper process of any PAC a variable named.
Source code in src/proxylib/env.py
75 76 77 78 | |