[Python-checkins] (no subject)

Stéphane Wirtel webhook-mailer at python.org
Fri Sep 13 10:07:10 EDT 2019




To: python-checkins at python.org
Subject: bpo-25068: urllib.request.ProxyHandler now lowercases the dict keys
 (GH-13489)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

https://github.com/python/cpython/commit/b761e3aed1fbada4572a776f6a0d3c4be491=
d595
commit: b761e3aed1fbada4572a776f6a0d3c4be491d595
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: St=C3=A9phane Wirtel <stephane at wirtel.be>
date: 2019-09-13T15:07:07+01:00
summary:

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

files:
A Misc/NEWS.d/next/Library/2019-05-22-04-52-35.bpo-25068.vR_rC-.rst
M Lib/test/test_urllib2.py
M Lib/urllib/request.py

diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index c228fa7d1dc1..186a96765971 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1342,21 +1342,22 @@ def http_open(self, req):
                 self.assertTrue(request.startswith(expected), repr(request))
=20
     def test_proxy(self):
-        o =3D OpenerDirector()
-        ph =3D urllib.request.ProxyHandler(dict(http=3D"proxy.example.com:31=
28"))
-        o.add_handler(ph)
-        meth_spec =3D [
-            [("http_open", "return response")]
-            ]
-        handlers =3D add_ordered_mock_handlers(o, meth_spec)
-
-        req =3D Request("http://acme.example.com/")
-        self.assertEqual(req.host, "acme.example.com")
-        o.open(req)
-        self.assertEqual(req.host, "proxy.example.com:3128")
-
-        self.assertEqual([(handlers[0], "http_open")],
-                         [tup[0:2] for tup in o.calls])
+        u =3D "proxy.example.com:3128"
+        for d in dict(http=3Du), dict(HTTP=3Du):
+            o =3D OpenerDirector()
+            ph =3D urllib.request.ProxyHandler(d)
+            o.add_handler(ph)
+            meth_spec =3D [
+                [("http_open", "return response")]
+                ]
+            handlers =3D add_ordered_mock_handlers(o, meth_spec)
+
+            req =3D Request("http://acme.example.com/")
+            self.assertEqual(req.host, "acme.example.com")
+            o.open(req)
+            self.assertEqual(req.host, u)
+            self.assertEqual([(handlers[0], "http_open")],
+                             [tup[0:2] for tup in o.calls])
=20
     def test_proxy_no_proxy(self):
         os.environ['no_proxy'] =3D 'python.org'
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 267a90dd80db..721c152179e9 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -792,6 +792,7 @@ def __init__(self, proxies=3DNone):
         assert hasattr(proxies, 'keys'), "proxies must be a mapping"
         self.proxies =3D proxies
         for type, url in proxies.items():
+            type =3D type.lower()
             setattr(self, '%s_open' % type,
                     lambda r, proxy=3Durl, type=3Dtype, meth=3Dself.proxy_op=
en:
                         meth(r, proxy, type))
diff --git a/Misc/NEWS.d/next/Library/2019-05-22-04-52-35.bpo-25068.vR_rC-.rs=
t b/Misc/NEWS.d/next/Library/2019-05-22-04-52-35.bpo-25068.vR_rC-.rst
new file mode 100644
index 000000000000..89de83bce029
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-05-22-04-52-35.bpo-25068.vR_rC-.rst
@@ -0,0 +1,2 @@
+:class:`urllib.request.ProxyHandler` now lowercases the keys of the passed
+dictionary.



More information about the Python-checkins mailing list