Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __del__(self):
lib.XXH32_freeState(self.xxhash_state)
import sys
import struct
import binascii
from xxhash._cffi import ffi, lib
PY3 = sys.version_info[0] == 3
XXHASH_VERSION = "%d.%d.%d" % (lib.XXH_VERSION_MAJOR,
lib.XXH_VERSION_MINOR,
lib.XXH_VERSION_RELEASE)
def _get_buffer(val):
"""
Best-effort function to get the pointer and byte length of a buffer-like
object.
"""
if PY3 and isinstance(val, str):
return val.encode('utf8'), len(val)
if isinstance(val, bytes):
return val, len(val)
cdata = ffi.from_buffer(val)
return cdata, len(cdata)