def test_proxy_no_proxy(self):
self.monkey_patch_environ("no_proxy", "python.org")
o = OpenerDirector()
ph = mechanize.ProxyHandler(dict(http="proxy.example.com"))
o.add_handler(ph)
req = Request("http://www.perl.org/")
self.assertEqual(req.get_host(), "www.perl.org")
r = o.open(req)
self.assertEqual(req.get_host(), "proxy.example.com")
req = Request("http://www.python.org")
self.assertEqual(req.get_host(), "www.python.org")
r = o.open(req)
if sys.version_info >= (2, 6):
# no_proxy environment variable not supported in python 2.5
self.assertEqual(req.get_host(), "www.python.org")
评论列表
文章目录