|
Lines 226-233
Link Here
|
| 226 |
# getproxies_environment use lowered case truncated (no '_proxy') keys |
226 |
# getproxies_environment use lowered case truncated (no '_proxy') keys |
| 227 |
self.assertEqual('localhost', proxies['no']) |
227 |
self.assertEqual('localhost', proxies['no']) |
| 228 |
# List of no_proxies with space. |
228 |
# List of no_proxies with space. |
| 229 |
self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com') |
229 |
self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com:1234') |
| 230 |
self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com')) |
230 |
self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com')) |
|
|
231 |
self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com:8888')) |
| 232 |
self.assertTrue(urllib.request.proxy_bypass_environment('newdomain.com:1234')) |
| 233 |
|
| 234 |
|
| 235 |
class ProxyTests_withOrderedEnv(unittest.TestCase): |
| 236 |
|
| 237 |
def setUp(self): |
| 238 |
# We need to test conditions, where variable order _is_ significant |
| 239 |
self._saved_env = os.environ |
| 240 |
# Monkey patch os.environ, start with empty fake environment |
| 241 |
os.environ = collections.OrderedDict() |
| 242 |
|
| 243 |
def tearDown(self): |
| 244 |
os.environ = self._saved_env |
| 245 |
|
| 246 |
def test_getproxies_environment_prefer_lowercase(self): |
| 247 |
# Test lowercase preference with removal |
| 248 |
os.environ['no_proxy'] = '' |
| 249 |
os.environ['No_Proxy'] = 'localhost' |
| 250 |
self.assertFalse(urllib.request.proxy_bypass_environment('localhost')) |
| 251 |
self.assertFalse(urllib.request.proxy_bypass_environment('arbitrary')) |
| 252 |
os.environ['http_proxy'] = '' |
| 253 |
os.environ['HTTP_PROXY'] = 'http://somewhere:3128' |
| 254 |
proxies = urllib.request.getproxies_environment() |
| 255 |
self.assertEqual({}, proxies) |
| 256 |
# Test lowercase preference of proxy bypass and correct matching including ports |
| 257 |
os.environ['no_proxy'] = 'localhost, noproxy.com, my.proxy:1234' |
| 258 |
os.environ['No_Proxy'] = 'xyz.com' |
| 259 |
self.assertTrue(urllib.request.proxy_bypass_environment('localhost')) |
| 260 |
self.assertTrue(urllib.request.proxy_bypass_environment('noproxy.com:5678')) |
| 261 |
self.assertTrue(urllib.request.proxy_bypass_environment('my.proxy:1234')) |
| 262 |
self.assertFalse(urllib.request.proxy_bypass_environment('my.proxy')) |
| 263 |
self.assertFalse(urllib.request.proxy_bypass_environment('arbitrary')) |
| 264 |
# Test lowercase preference with replacement |
| 265 |
os.environ['http_proxy'] = 'http://somewhere:3128' |
| 266 |
os.environ['Http_Proxy'] = 'http://somewhereelse:3128' |
| 267 |
proxies = urllib.request.getproxies_environment() |
| 268 |
self.assertEqual('http://somewhere:3128', proxies['http']) |
| 231 |
|
269 |
|
| 232 |
class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin, FakeFTPMixin): |
270 |
class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin, FakeFTPMixin): |
| 233 |
"""Test urlopen() opening a fake http connection.""" |
271 |
"""Test urlopen() opening a fake http connection.""" |