Skip to content
Myr

Split get_environ_proxies into two methods.

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

This makes it possible to get at the no_proxy logic separately.

authored by Cory Benfield · committed by Cory Benfield · parent 03f444e · Browse files · 1 file+15 added−10 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+15 added−10 removed

  • other:+15 added−10 removed

1 file+15 added−10 removed

modified:requests/utils.py+15 added-10 removed
464 unmodified lines
465 return False466 return True467468469def get_environ_proxies(url):470 """Return a dict of environment proxies."""471469def should_bypass_proxies(url):470 """471 Returns whether we should bypass proxies or not.472 """473 get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper())474475 # First check whether no_proxy is defined. If it is, check that the URL476 # we're getting isn't in the no_proxy list.
9 unmodified lines
486 if is_ipv4_address(ip):487 for proxy_ip in no_proxy:488 if is_valid_cidr(proxy_ip):489 if address_in_network(ip, proxy_ip):489 return {}490 return True491 else:492 for host in no_proxy:493 if netloc.endswith(host) or netloc.split(':')[0].endswith(host):494 # The URL does match something in no_proxy, so we don't want495 # to apply the proxies on this URL.495 return {}496 return True497498 # If the system proxy settings indicate that this URL should be bypassed,499 # don't proxy.500 # The proxy_bypass function is incredibly buggy on OS X in early versions
5 unmodified lines
506 except (TypeError, socket.gaierror):507 bypass = False508509 if bypass:509 return {}510 return True511511 # If we get here, we either didn't have no_proxy set or we're not going512 # anywhere that no_proxy applies to, and the system settings don't require513 # bypassing the proxy for the current URL.514 return getproxies()512 return False513514def get_environ_proxies(url):515 """Return a dict of environment proxies."""516 if should_bypass_proxies(url):517 return {}518 else:519 return getproxies()520521522def default_user_agent(name="python-requests"):523 """Return a string representing the default user agent."""524 _implementation = platform.python_implementation()525
143 unmodified lines