#3879 fix a regression in urllib.getproxies_environment

reviewers: Benjamin, Georg
This commit is contained in:
Benjamin Peterson 2008-09-21 21:27:51 +00:00
parent 1672e10dc2
commit 2c7470d951
3 changed files with 28 additions and 3 deletions

View File

@ -94,6 +94,31 @@ class urlopen_FileTests(unittest.TestCase):
for line in self.returned_obj.__iter__(): for line in self.returned_obj.__iter__():
self.assertEqual(line, self.text) self.assertEqual(line, self.text)
class ProxyTests(unittest.TestCase):
def setUp(self):
unittest.TestCase.setUp(self)
# Save all proxy related env vars
self._saved_environ = dict([(k, v) for k, v in os.environ.iteritems()
if k.lower().find('proxy') >= 0])
# Delete all proxy related env vars
for k in self._saved_environ:
del os.environ[k]
def tearDown(self):
unittest.TestCase.tearDown(self)
# Restore all proxy related env vars
for k, v in self._saved_environ:
os.environ[k] = v
def test_getproxies_environment_keep_no_proxies(self):
os.environ['NO_PROXY'] = 'localhost'
proxies = urllib.getproxies_environment()
# getproxies_environment use lowered case truncated (no '_proxy') keys
self.assertEquals('localhost', proxies['no'])
class urlopen_HttpTests(unittest.TestCase): class urlopen_HttpTests(unittest.TestCase):
"""Test urlopen() opening a fake http connection.""" """Test urlopen() opening a fake http connection."""
@ -648,6 +673,7 @@ def test_main():
urlopen_FileTests, urlopen_FileTests,
urlopen_HttpTests, urlopen_HttpTests,
urlretrieve_FileTests, urlretrieve_FileTests,
ProxyTests,
QuotingTests, QuotingTests,
UnquotingTests, UnquotingTests,
urlencode_Tests, urlencode_Tests,

View File

@ -1299,9 +1299,6 @@ def getproxies_environment():
proxies = {} proxies = {}
for name, value in os.environ.items(): for name, value in os.environ.items():
name = name.lower() name = name.lower()
if name == 'no_proxy':
# handled in proxy_bypass_environment
continue
if value and name[-6:] == '_proxy': if value and name[-6:] == '_proxy':
proxies[name[:-6]] = value proxies[name[:-6]] = value
return proxies return proxies

View File

@ -15,6 +15,8 @@ Core and Builtins
Library Library
------- -------
- Issue #3879: A regression in urllib.getproxies_enviroment was fixed.
Build Build
----- -----