Skip to content
Myr

A utility function to fetch environment proxies

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

This adds support for lowercase environment proxy variables (which are quite popular too). It returns proxies in a format compatible with request's proxy parameter. Moreover, it can be used in the request models for proxy defaults.

authored by Rohan Jain · committed by Rohan Jain · parent 317f64a · Browse files · 1 file+16 added−0 removed
This commit

State

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

Trailers

  • Signed-off-by: Rohan Jain <crodjer@gmail.com>

Diff stats

1 file+16 added−0 removed

  • other:+16 added−0 removed

1 file+16 added−0 removed

modified:requests/utils.py+16 added
444 unmodified lines
445 # Unquote only the unreserved characters446 # Then quote only illegal characters (do not quote reserved, unreserved,447 # or '%')448 return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~")449450def get_environ_proxies():451 """Return a dict of environment proxies."""452453 proxy_keys = [454 'all',455 'http',456 'https',457 'ftp',458 'socks',459 'no'460 ]461462 get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper())463 proxies = [(key, get_proxy(key + '_proxy')) for key in proxy_keys]464 return dict([(key, val) for (key, val) in proxies if val])