1b2732e9dSimarom"""Import basic exposure of libzmq C API as a backend"""
2b2732e9dSimarom
3b2732e9dSimarom# Copyright (C) PyZMQ Developers
4b2732e9dSimarom# Distributed under the terms of the Modified BSD License.
5b2732e9dSimarom
6b2732e9dSimarompublic_api = [
7b2732e9dSimarom    'Context',
8b2732e9dSimarom    'Socket',
9b2732e9dSimarom    'Frame',
10b2732e9dSimarom    'Message',
11b2732e9dSimarom    'Stopwatch',
12b2732e9dSimarom    'device',
13b2732e9dSimarom    'proxy',
14b2732e9dSimarom    'zmq_poll',
15b2732e9dSimarom    'strerror',
16b2732e9dSimarom    'zmq_errno',
17b2732e9dSimarom    'has',
18b2732e9dSimarom    'curve_keypair',
19b2732e9dSimarom    'constants',
20b2732e9dSimarom    'zmq_version_info',
21b2732e9dSimarom    'IPC_PATH_MAX_LEN',
22b2732e9dSimarom]
23b2732e9dSimarom
24b2732e9dSimaromdef select_backend(name):
25b2732e9dSimarom    """Select the pyzmq backend"""
26b2732e9dSimarom    try:
27b2732e9dSimarom        mod = __import__(name, fromlist=public_api)
28b2732e9dSimarom    except ImportError:
29b2732e9dSimarom        raise
30b2732e9dSimarom    except Exception as e:
31b2732e9dSimarom        import sys
32b2732e9dSimarom        from zmq.utils.sixcerpt import reraise
33b2732e9dSimarom        exc_info = sys.exc_info()
34b2732e9dSimarom        reraise(ImportError, ImportError("Importing %s failed with %s" % (name, e)), exc_info[2])
35b2732e9dSimarom
36b2732e9dSimarom    ns = {}
37b2732e9dSimarom    for key in public_api:
38b2732e9dSimarom        ns[key] = getattr(mod, key)
39b2732e9dSimarom    return ns
40