select.py 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Import basic exposure of libzmq C API as a backend"""
  2. # Copyright (C) PyZMQ Developers
  3. # Distributed under the terms of the Modified BSD License.
  4. from importlib import import_module
  5. from typing import Dict
  6. public_api = [
  7. 'Context',
  8. 'Socket',
  9. 'Frame',
  10. 'Message',
  11. 'proxy',
  12. 'proxy_steerable',
  13. 'zmq_poll',
  14. 'strerror',
  15. 'zmq_errno',
  16. 'has',
  17. 'curve_keypair',
  18. 'curve_public',
  19. 'zmq_version_info',
  20. 'IPC_PATH_MAX_LEN',
  21. 'PYZMQ_DRAFT_API',
  22. ]
  23. def select_backend(name: str) -> Dict:
  24. """Select the pyzmq backend"""
  25. try:
  26. mod = import_module(name)
  27. except ImportError:
  28. raise
  29. except Exception as e:
  30. raise ImportError(f"Importing {name} failed with {e}") from e
  31. ns = {
  32. # private API
  33. 'monitored_queue': mod.monitored_queue,
  34. }
  35. ns.update({key: getattr(mod, key) for key in public_api})
  36. return ns