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 <rep...@bugs.python.org> <http://bugs.python.org/issue19259> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com