diff options
author | Cory Benfield <lukasaoz@gmail.com> | 2014-03-12 19:20:12 +0000 |
---|---|---|
committer | Cory Benfield <lukasaoz@gmail.com> | 2014-03-12 19:20:12 +0000 |
commit | 6d7e8a97bbefa287366bc5d0b0b8f789532e853a (patch) | |
tree | 2b1db86fe3bf3f745f8fbacb5c37523a90f0ab55 | |
parent | 03f444e601e6608f68f3a09d708af93e4512560a (diff) | |
download | python-requests-6d7e8a97bbefa287366bc5d0b0b8f789532e853a.tar.gz |
Split get_environ_proxies into two methods.
This makes it possible to get at the no_proxy logic separately.
-rw-r--r-- | requests/utils.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/requests/utils.py b/requests/utils.py index 7b7ff0a7..1095b3e7 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -466,9 +466,10 @@ def is_valid_cidr(string_network): return True -def get_environ_proxies(url): - """Return a dict of environment proxies.""" - +def should_bypass_proxies(url): + """ + Returns whether we should bypass proxies or not. + """ get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper()) # First check whether no_proxy is defined. If it is, check that the URL @@ -486,13 +487,13 @@ def get_environ_proxies(url): for proxy_ip in no_proxy: if is_valid_cidr(proxy_ip): if address_in_network(ip, proxy_ip): - return {} + return True else: for host in no_proxy: if netloc.endswith(host) or netloc.split(':')[0].endswith(host): # The URL does match something in no_proxy, so we don't want # to apply the proxies on this URL. - return {} + return True # If the system proxy settings indicate that this URL should be bypassed, # don't proxy. @@ -506,12 +507,16 @@ def get_environ_proxies(url): bypass = False if bypass: - return {} + return True - # If we get here, we either didn't have no_proxy set or we're not going - # anywhere that no_proxy applies to, and the system settings don't require - # bypassing the proxy for the current URL. - return getproxies() + return False + +def get_environ_proxies(url): + """Return a dict of environment proxies.""" + if should_bypass_proxies(url): + return {} + else: + return getproxies() def default_user_agent(name="python-requests"): |