_ffi.py 738 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # coding: utf-8
  2. """
  3. FFI helper compatibility functions. Exports the following items:
  4. - LibraryNotFoundError
  5. - FFIEngineError
  6. - bytes_from_buffer()
  7. - buffer_from_bytes()
  8. - null()
  9. """
  10. from __future__ import unicode_literals, division, absolute_import, print_function
  11. from ctypes import create_string_buffer
  12. def buffer_from_bytes(initializer):
  13. return create_string_buffer(initializer)
  14. def bytes_from_buffer(buffer, maxlen=None):
  15. return buffer.raw
  16. def null():
  17. return None
  18. class LibraryNotFoundError(Exception):
  19. """
  20. An exception when trying to find a shared library
  21. """
  22. pass
  23. class FFIEngineError(Exception):
  24. """
  25. An exception when trying to instantiate ctypes or cffi
  26. """
  27. pass