merge from 3.2 - Fix closes issue12698 - make the no_proxy environment variable handling a bit lenient (accomodate spaces in between the items)

This commit is contained in:
Senthil Kumaran 2011-08-06 12:28:16 +08:00
commit 0c8108914e
2 changed files with 5 additions and 2 deletions

View File

@ -135,7 +135,9 @@ def test_getproxies_environment_keep_no_proxies(self):
proxies = urllib.request.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.request.proxy_bypass_environment('anotherdomain.com'))
class urlopen_HttpTests(unittest.TestCase):
"""Test urlopen() opening a fake http connection."""

View File

@ -2274,7 +2274,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