Test if proxies should not be used for a particular host. Checks the proxy dict for the value of no_proxy, which should be a list of comma separated DNS suffixes, or '*' for all hosts.
(host, proxies=None)
| 1909 | return proxies |
| 1910 | |
| 1911 | def proxy_bypass_environment(host, proxies=None): |
| 1912 | """Test if proxies should not be used for a particular host. |
| 1913 | |
| 1914 | Checks the proxy dict for the value of no_proxy, which should |
| 1915 | be a list of comma separated DNS suffixes, or '*' for all hosts. |
| 1916 | |
| 1917 | """ |
| 1918 | if proxies is None: |
| 1919 | proxies = getproxies_environment() |
| 1920 | # don't bypass, if no_proxy isn't specified |
| 1921 | try: |
| 1922 | no_proxy = proxies['no'] |
| 1923 | except KeyError: |
| 1924 | return False |
| 1925 | # '*' is special case for always bypass |
| 1926 | if no_proxy == '*': |
| 1927 | return True |
| 1928 | host = host.lower() |
| 1929 | # strip port off host |
| 1930 | hostonly, port = _splitport(host) |
| 1931 | # check if the host ends with any of the DNS suffixes |
| 1932 | for name in no_proxy.split(','): |
| 1933 | name = name.strip() |
| 1934 | if name: |
| 1935 | name = name.lstrip('.') # ignore leading dots |
| 1936 | name = name.lower() |
| 1937 | if hostonly == name or host == name: |
| 1938 | return True |
| 1939 | name = '.' + name |
| 1940 | if hostonly.endswith(name) or host.endswith(name): |
| 1941 | return True |
| 1942 | # otherwise, don't bypass |
| 1943 | return False |
| 1944 | |
| 1945 | |
| 1946 | # This code tests an OSX specific data structure but is testable on all |
no test coverage detected
searching dependent graphs…