import hmac
def safe_compare(one, two):
# Do encode here to avoid spawning core
try:
one = one.encode()
except AttributeError:
pass
two = two.encode()
return hmac.compare_digest(one, two)