__init__.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright 2013-2025 The py-lmdb authors, all rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted only as authorized by the OpenLDAP
  5. # Public License.
  6. #
  7. # A copy of this license is available in the file LICENSE in the
  8. # top-level directory of the distribution or, alternatively, at
  9. # <http://www.OpenLDAP.org/license.html>.
  10. #
  11. # OpenLDAP is a registered trademark of the OpenLDAP Foundation.
  12. #
  13. # Individual files and/or contributed packages may be copyright by
  14. # other parties and/or subject to additional restrictions.
  15. #
  16. # This work also contains materials derived from public sources.
  17. #
  18. # Additional information about OpenLDAP can be obtained at
  19. # <http://www.openldap.org/>.
  20. """
  21. Python wrapper for OpenLDAP's "Lightning" MDB database.
  22. Please see https://lmdb.readthedocs.io/
  23. """
  24. import os
  25. import sys
  26. def _reading_docs():
  27. # Hack: disable speedups while testing or reading docstrings. Don't check
  28. # for basename for embedded python - variable 'argv' does not exists there or is empty.
  29. if not(hasattr(sys, 'argv')) or not sys.argv:
  30. return False
  31. basename = os.path.basename(sys.argv[0])
  32. return any(x in basename for x in ('sphinx-build', 'pydoc'))
  33. try:
  34. if _reading_docs() or os.getenv('LMDB_FORCE_CFFI') is not None:
  35. raise ImportError
  36. from lmdb.cpython import *
  37. from lmdb.cpython import open
  38. from lmdb.cpython import __all__
  39. except ImportError:
  40. if (not _reading_docs()) and os.getenv('LMDB_FORCE_CPYTHON') is not None:
  41. raise
  42. from lmdb.cffi import *
  43. from lmdb.cffi import open
  44. from lmdb.cffi import __all__
  45. from lmdb.cffi import __doc__
  46. __version__ = '1.7.5'