werkzeug里的safe_str_cmp函数意义是什么?
代码如下:def safe_str_cmp(a, b):
if isinstance(a, str):
a = a.encode("utf-8")
if isinstance(b, str):
b = b.encode("utf-8")
if len(a) != len(b):
return False
rv = 0
for x, y in zip(a, b):
rv |= x ^ y
return rv == 0
和 is 或 == 有什么不同?
注释为:
"""This function compares strings in somewhat constant time.This
requires that the length of at least one string is known in advance.
Returns `True` if the two strings are equal, or `False` if they are not.
.. versionadded:: 0.7
"""
在注释里没有看出来有对字符串进行什么特别的比较,请问大佬们,这个函数的意义何在呢?
页:
[1]