1"""Import basic exposure of libzmq C API as a backend"""
2
3# Copyright (C) PyZMQ Developers
4# Distributed under the terms of the Modified BSD License.
5
6import os
7import platform
8
9from .select import public_api, select_backend
10
11if 'PYZMQ_BACKEND' in os.environ:
12 backend = os.environ['PYZMQ_BACKEND']
13 if backend in ('cython', 'cffi'):
14 backend = f'zmq.backend.{backend}'
15 _ns = select_backend(backend)
16else:
17 # default to cython, fallback to cffi
18 # (reverse on PyPy)
19 if platform.python_implementation() == 'PyPy':
20 first, second = ('zmq.backend.cffi', 'zmq.backend.cython')
21 else:
22 first, second = ('zmq.backend.cython', 'zmq.backend.cffi')
23
24 try:
25 _ns = select_backend(first)
26 except Exception as original_error:
27 try:
28 _ns = select_backend(second)
29 except ImportError:
30 raise original_error from None
31
32globals().update(_ns)
33
34__all__ = public_api