Commit b761e3ae authored by Zackery Spytz's avatar Zackery Spytz Committed by Stéphane Wirtel

bpo-25068: urllib.request.ProxyHandler now lowercases the dict keys (GH-13489)

parent 693aa80a
...@@ -1342,21 +1342,22 @@ class HandlerTests(unittest.TestCase): ...@@ -1342,21 +1342,22 @@ class HandlerTests(unittest.TestCase):
self.assertTrue(request.startswith(expected), repr(request)) self.assertTrue(request.startswith(expected), repr(request))
def test_proxy(self): def test_proxy(self):
o = OpenerDirector() u = "proxy.example.com:3128"
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com:3128")) for d in dict(http=u), dict(HTTP=u):
o.add_handler(ph) o = OpenerDirector()
meth_spec = [ ph = urllib.request.ProxyHandler(d)
[("http_open", "return response")] o.add_handler(ph)
] meth_spec = [
handlers = add_ordered_mock_handlers(o, meth_spec) [("http_open", "return response")]
]
req = Request("http://acme.example.com/") handlers = add_ordered_mock_handlers(o, meth_spec)
self.assertEqual(req.host, "acme.example.com")
o.open(req) req = Request("http://acme.example.com/")
self.assertEqual(req.host, "proxy.example.com:3128") self.assertEqual(req.host, "acme.example.com")
o.open(req)
self.assertEqual([(handlers[0], "http_open")], self.assertEqual(req.host, u)
[tup[0:2] for tup in o.calls]) self.assertEqual([(handlers[0], "http_open")],
[tup[0:2] for tup in o.calls])
def test_proxy_no_proxy(self): def test_proxy_no_proxy(self):
os.environ['no_proxy'] = 'python.org' os.environ['no_proxy'] = 'python.org'
......
...@@ -792,6 +792,7 @@ class ProxyHandler(BaseHandler): ...@@ -792,6 +792,7 @@ class ProxyHandler(BaseHandler):
assert hasattr(proxies, 'keys'), "proxies must be a mapping" assert hasattr(proxies, 'keys'), "proxies must be a mapping"
self.proxies = proxies self.proxies = proxies
for type, url in proxies.items(): for type, url in proxies.items():
type = type.lower()
setattr(self, '%s_open' % type, setattr(self, '%s_open' % type,
lambda r, proxy=url, type=type, meth=self.proxy_open: lambda r, proxy=url, type=type, meth=self.proxy_open:
meth(r, proxy, type)) meth(r, proxy, type))
......
:class:`urllib.request.ProxyHandler` now lowercases the keys of the passed
dictionary.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment