Title: Ignore case when checking algorithm in urllib2
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.5
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: BitTorment, georg.brandl, terry.reedy, zathras
Priority: normal Keywords: patch

Created on 2008-04-26 08:47 by zathras, last changed 2008-05-04 21:40 by georg.brandl. This issue is now closed.

File name Uploaded Description Edit
case_insensitive_algorithm.patch BitTorment, 2008-05-04 13:20 Proposed patch
Messages (6)
msg65836 - (view) Author: david reid (zathras) Date: 2008-04-26 08:47
Small change to allow get_algorithm_impls to correctly detect when lower
case algorithm strings are passed. I recently ran into a server that
sent 'md5' and so this function failed without this small change.

    def get_algorithm_impls(self, algorithm):
        # lambdas assume digest modules are imported at the top level
        if algorithm.lower() == 'md5':
            H = lambda x: hashlib.md5(x).hexdigest()
        elif algorithm.lower() == 'sha':
            H = lambda x: hashlib.sha1(x).hexdigest()
msg66114 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2008-05-02 21:37
Function is about 2/3rds down in urllib2.

Note 1: hashlib checks upper and lower case versions of names.
So this seems like reasonable request.

Note 2: I would start hashlib.__get_builtin_constructor(name):
with 'name = name.lower()'
and replace first two 'name in' constructions with 'name =='
and shrink 2nd two lists.

Note 3. I would do same with get_algorithm_impls():
   algorithm = algorithm.lower()
Instead of possibly calling .lower twice.

Note 4: I consider 'name = lambda ...' inferior to 'def name...'
but I am not the one who will edit this.

Keyword says patch, but I do not see one.
msg66115 - (view) Author: david reid (zathras) Date: 2008-05-02 21:44
The patch is inline. There's not much to it :-)

Agree with your suggestion to avoid calling lower() twice.
msg66207 - (view) Author: Martin McNickle (BitTorment) Date: 2008-05-04 13:20
RFC2617 says that the authentication scheme should be case insensitive.
 Included is a patch which changes the string to uppercase before
msg66212 - (view) Author: david reid (zathras) Date: 2008-05-04 15:00
Looks like a sensible, simple fix to me :-)
msg66243 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-04 21:40
Applied in r62713.
Date User Action Args
2008-05-04 21:40:52georg.brandlsetstatus: open -> closed
resolution: accepted
messages: + msg66243
nosy: + georg.brandl
2008-05-04 15:00:59zathrassetmessages: + msg66212
2008-05-04 13:20:56BitTormentsetfiles: + case_insensitive_algorithm.patch
keywords: + patch
messages: + msg66207
nosy: + BitTorment
2008-05-02 21:44:06zathrassetmessages: + msg66115
2008-05-02 21:37:46terry.reedysetmessages: + msg66114
2008-05-02 21:34:40terry.reedysetmessages: - msg66113
2008-05-02 21:34:32terry.reedysetmessages: - msg66110
2008-05-02 21:32:21terry.reedysetmessages: + msg66113
2008-05-02 21:07:49terry.reedysetnosy: + terry.reedy
messages: + msg66110
2008-04-26 08:47:17zathrascreate