MCPcopy Index your code
hub / github.com/python/cpython / getproxies_environment

Function getproxies_environment

Lib/urllib/request.py:1876–1909  ·  view source on GitHub ↗

Return a dictionary of scheme -> proxy server URL mappings. Scan the environment for variables named _proxy; this seems to be the standard convention.

()

Source from the content-addressed store, hash-verified

1874
1875# Proxy handling
1876def getproxies_environment():
1877 """Return a dictionary of scheme -> proxy server URL mappings.
1878
1879 Scan the environment for variables named <scheme>_proxy;
1880 this seems to be the standard convention.
1881 """
1882 # in order to prefer lowercase variables, process environment in
1883 # two passes: first matches any, second pass matches lowercase only
1884
1885 # select only environment variables which end in (after making lowercase) _proxy
1886 proxies = {}
1887 environment = []
1888 for name in os.environ:
1889 # fast screen underscore position before more expensive case-folding
1890 if len(name) > 5 and name[-6] == "_" and name[-5:].lower() == "proxy":
1891 value = os.environ[name]
1892 proxy_name = name[:-6].lower()
1893 environment.append((name, value, proxy_name))
1894 if value:
1895 proxies[proxy_name] = value
1896 # CVE-2016-1000110 - If we are running as CGI script, forget HTTP_PROXY
1897 # (non-all-lowercase) as it may be set from the web server by a "Proxy:"
1898 # header from the client
1899 # If "proxy" is lowercase, it will still be used thanks to the next block
1900 if 'REQUEST_METHOD' in os.environ:
1901 proxies.pop('http', None)
1902 for name, value, proxy_name in environment:
1903 # not case-folded, checking here for lower-case env vars only
1904 if name[-6:] == '_proxy':
1905 if value:
1906 proxies[proxy_name] = value
1907 else:
1908 proxies.pop(proxy_name, None)
1909 return proxies
1910
1911def proxy_bypass_environment(host, proxies=None):
1912 """Test if proxies should not be used for a particular host.

Callers 3

proxy_bypass_environmentFunction · 0.85
proxy_bypassFunction · 0.85
getproxiesFunction · 0.85

Calls 3

lowerMethod · 0.45
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…