This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: The proxy key's string should ignore case.
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Chuang Cao, Rosuav, ZackerySpytz, martin.panter, matrixise, miss-islington
Priority: normal Keywords: patch

Created on 2015-09-11 08:46 by Chuang Cao, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13489 merged ZackerySpytz, 2019-05-22 10:54
PR 16107 closed miss-islington, 2019-09-13 14:07
Messages (7)
msg250454 - (view) Author: Chuang Cao (Chuang Cao) Date: 2015-09-11 08:46
When use a urllib2.ProxyHandler to set a proxy, if the proxies's key is an upper string, like "HTTP", "HTTPS". The proxy url can't be used, because they can't find the <type>_open function.

Two way can sovle the issue.
1. Specify it in document to let users to use a lower string like "http".

2. Add a patch in urllib2.py:

diff -up ./urllib2.py.orig ./urllib2.py
--- ./urllib2.py.orig	2015-09-11 15:06:55.686927934 +0800
+++ ./urllib2.py	2015-09-11 16:56:48.306138898 +0800
@@ -102,6 +102,7 @@ import sys
 import time
 import urlparse
 import bisect
+import string
 
 try:
     from cStringIO import StringIO
@@ -713,6 +714,7 @@ class ProxyHandler(BaseHandler):
         assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
         self.proxies = proxies
         for type, url in proxies.items():
+            type = string.lower(type)
             setattr(self, '%s_open' % type,
                     lambda r, proxy=url, type=type, meth=self.proxy_open: \
                     meth(r, proxy, type))


I think the second way is a good way.
msg250455 - (view) Author: Chris Angelico (Rosuav) * Date: 2015-09-11 09:02
This sounds like a feature enhancement, which means it (almost certainly) won't be applied to Python 2.7. Does the same question come up in Python 3?

Also (FWIW) if you can confidently assume that all the keys are strings. then type.lower() is better than string.lower(type).
msg250458 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-09-11 09:50
Looking at the code, I think Python 3 is in the same boat. Most things in Python are case-sensitive, but I think it is reasonable to make an exception here, since the protocol schemes in general are insensitive. E.g. urlopen("HTTPS://bugs.python.org/issue25068") still uses "https" internally.

It would be good to include a test case and a note in the documentation if we added this though.
msg250459 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-09-11 09:52
On the other hand, a documentation update saying it has to be lower case would be fine for Python 2.7 and 3.4+, if you wanted to go that way.
msg352336 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-09-13 14:07
New changeset b761e3aed1fbada4572a776f6a0d3c4be491d595 by Stéphane Wirtel (Zackery Spytz) in branch 'master':
bpo-25068: urllib.request.ProxyHandler now lowercases the dict keys (GH-13489)
https://github.com/python/cpython/commit/b761e3aed1fbada4572a776f6a0d3c4be491d595
msg352337 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-09-13 14:12
Thank you for your contribution, your PR has been merged into master but not in 3.8.
msg352339 - (view) Author: miss-islington (miss-islington) Date: 2019-09-13 14:26
New changeset 590ed09a5b422d59cc1f049c64ac30733545eef0 by Miss Islington (bot) in branch '3.8':
bpo-25068: urllib.request.ProxyHandler now lowercases the dict keys (GH-13489)
https://github.com/python/cpython/commit/590ed09a5b422d59cc1f049c64ac30733545eef0
History
Date User Action Args
2022-04-11 14:58:20adminsetgithub: 69254
2019-09-13 14:26:03miss-islingtonsetnosy: + miss-islington
messages: + msg352339
2019-09-13 14:12:08matrixisesetstatus: open -> closed
resolution: fixed
messages: + msg352337

stage: patch review -> resolved
2019-09-13 14:07:19miss-islingtonsetpull_requests: + pull_request15725
2019-09-13 14:07:10matrixisesetnosy: + matrixise
messages: + msg352336
2019-05-22 11:15:01ZackerySpytzsetnosy: + ZackerySpytz

versions: + Python 3.8, - Python 3.6
2019-05-22 10:54:29ZackerySpytzsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request13405
2015-09-11 09:52:58martin.pantersetmessages: + msg250459
2015-09-11 09:50:40martin.pantersetversions: + Python 3.6, - Python 2.7
nosy: + martin.panter

messages: + msg250458

type: resource usage -> enhancement
stage: needs patch
2015-09-11 09:02:49Rosuavsetnosy: + Rosuav
messages: + msg250455
2015-09-11 08:46:13Chuang Caocreate