Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)