def isHex(val: str) -> bool:
"""
Return whether the given str represents a hex value or not
:param val: the string to check
:return: whether the given str represents a hex value
"""
if isinstance(val, bytes):
# only decodes utf-8 string
try:
val = val.decode()
except ValueError:
return False
return isinstance(val, str) and all(c in string.hexdigits for c in val)
# decorator
评论列表
文章目录