Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore case when checking algorithm in urllib2 #46947

Closed
zathras mannequin opened this issue Apr 26, 2008 · 6 comments
Closed

Ignore case when checking algorithm in urllib2 #46947

zathras mannequin opened this issue Apr 26, 2008 · 6 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@zathras
Copy link
Mannequin

zathras mannequin commented Apr 26, 2008

BPO 2695
Nosy @birkenfeld, @terryjreedy
Files
  • case_insensitive_algorithm.patch: Proposed patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-05-04.21:40:52.730>
    created_at = <Date 2008-04-26.08:47:17.551>
    labels = ['type-bug', 'library']
    title = 'Ignore case when checking algorithm in urllib2'
    updated_at = <Date 2008-05-04.21:40:52.693>
    user = 'https://bugs.python.org/zathras'

    bugs.python.org fields:

    activity = <Date 2008-05-04.21:40:52.693>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-05-04.21:40:52.730>
    closer = 'georg.brandl'
    components = ['Library (Lib)']
    creation = <Date 2008-04-26.08:47:17.551>
    creator = 'zathras'
    dependencies = []
    files = ['10189']
    hgrepos = []
    issue_num = 2695
    keywords = ['patch']
    message_count = 6.0
    messages = ['65836', '66114', '66115', '66207', '66212', '66243']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'terry.reedy', 'zathras', 'BitTorment']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2695'
    versions = ['Python 2.5']

    @zathras
    Copy link
    Mannequin Author

    zathras mannequin commented Apr 26, 2008

    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()
            ...

    @zathras zathras mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 26, 2008
    @terryjreedy
    Copy link
    Member

    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.

    @zathras
    Copy link
    Mannequin Author

    zathras mannequin commented May 2, 2008

    The patch is inline. There's not much to it :-)

    Agree with your suggestion to avoid calling lower() twice.

    @BitTorment
    Copy link
    Mannequin

    BitTorment mannequin commented May 4, 2008

    RFC2617 says that the authentication scheme should be case insensitive.
    Included is a patch which changes the string to uppercase before
    comparison.

    @zathras
    Copy link
    Mannequin Author

    zathras mannequin commented May 4, 2008

    Looks like a sensible, simple fix to me :-)

    @birkenfeld
    Copy link
    Member

    Applied in r62713.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants