From b5bd4c88b5de771647cc644b4e50e701cadba08c Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Sat, 6 Aug 2011 12:24:33 +0800 Subject: [PATCH] Fix closes issue12698 - make the no_proxy environment variable handling a bit lenient (accomodate spaces in between the items) --- Lib/test/test_urllib.py | 3 +++ Lib/urllib.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index e7e54a2dd8..401dd5ca0c 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -114,6 +114,9 @@ class ProxyTests(unittest.TestCase): proxies = urllib.getproxies_environment() # getproxies_environment use lowered case truncated (no '_proxy') keys self.assertEqual('localhost', proxies['no']) + # List of no_proxies with space. + self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com') + self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com')) class urlopen_HttpTests(unittest.TestCase): diff --git a/Lib/urllib.py b/Lib/urllib.py index aac235da2c..1261ec14a1 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -1366,7 +1366,8 @@ def proxy_bypass_environment(host): # strip port off host hostonly, port = splitport(host) # check if the host ends with any of the DNS suffixes - for name in no_proxy.split(','): + no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')] + for name in no_proxy_list: if name and (hostonly.endswith(name) or host.endswith(name)): return 1 # otherwise, don't bypass -- 2.50.1