[New-bugs-announce] [issue19259] Provide Python implementation of operator.compare_digest()

Christian Heimes report at bugs.python.org
Mon Oct 14 13:30:56 CEST 2013


New submission from Christian Heimes:

The operator module doesn't have a Python implementation of _compare_digest. This code mimicks the C code:

def _compare_digest(a, b):
    if isinstance(a, str) and isinstance(b, str):
        a = a.encode("ascii")
        b = b.encode("ascii")
    a = memoryview(a)
    len_a = len(a)
    right = memoryview(b)
    len_b = len(right)
    if len_a == len_b:
        result = 0
        left = a
    # loop count depends on length of b
    if len_a != len_b:
        result = 1
        left = b
    for l, r in zip(left, right):
        result |= l ^ r
    return result == 0

----------
messages: 199868
nosy: christian.heimes, pitrou, serhiy.storchaka
priority: normal
severity: normal
stage: needs patch
status: open
title: Provide Python implementation of operator.compare_digest()
type: enhancement
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19259>
_______________________________________


More information about the New-bugs-announce mailing list