~myers-1/pyopenssl/npn

140.1.4 by Jean-Paul Calderone
Update copyright headers; remove pointless dates, add a pointer to the LICENSE file.
1
# Copyright (C) AB Strakt
2
# See LICENSE for details.
3
1 by Jean-Paul Calderone
initial source import
4
"""
5
pyOpenSSL - A simple wrapper around the OpenSSL library
6
"""
132.2.12 by Jean-Paul Calderone
Hack up module import like mad
7
8
import sys
137.3.1 by Jean-Paul Calderone
Try to get RTLD_NOW and RTLD_GLOBAL from a real definition - DLFCN or dl or ctypes
9
132.2.50 by Jean-Paul Calderone
Try to support Windows here - ie, do not do any of the dl flags stuff
10
try:
11
    orig = sys.getdlopenflags()
12
except AttributeError:
137.3.1 by Jean-Paul Calderone
Try to get RTLD_NOW and RTLD_GLOBAL from a real definition - DLFCN or dl or ctypes
13
    from OpenSSL import crypto
132.2.50 by Jean-Paul Calderone
Try to support Windows here - ie, do not do any of the dl flags stuff
14
else:
137.3.1 by Jean-Paul Calderone
Try to get RTLD_NOW and RTLD_GLOBAL from a real definition - DLFCN or dl or ctypes
15
    try:
16
        import DLFCN
17
    except ImportError:
18
        try:
19
            import dl
20
        except ImportError:
21
            try:
22
                import ctypes
23
            except ImportError:
24
                flags = 2 | 256
25
            else:
26
                flags = 2 | ctypes.RTLD_GLOBAL
27
                del ctypes
28
        else:
29
            flags = dl.RTLD_NOW | dl.RTLD_GLOBAL
30
            del dl
31
    else:
32
        flags = DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL
33
        del DLFCN
34
35
    sys.setdlopenflags(flags)
132.2.50 by Jean-Paul Calderone
Try to support Windows here - ie, do not do any of the dl flags stuff
36
    from OpenSSL import crypto
37
    sys.setdlopenflags(orig)
137.3.1 by Jean-Paul Calderone
Try to get RTLD_NOW and RTLD_GLOBAL from a real definition - DLFCN or dl or ctypes
38
    del orig, flags
132.2.52 by Jean-Paul Calderone
Only delete orig if it was defined
39
del sys
132.2.12 by Jean-Paul Calderone
Hack up module import like mad
40
137.3.1 by Jean-Paul Calderone
Try to get RTLD_NOW and RTLD_GLOBAL from a real definition - DLFCN or dl or ctypes
41
from OpenSSL import rand, SSL
132.2.12 by Jean-Paul Calderone
Hack up module import like mad
42
from OpenSSL.version import __version__
43
44
__all__ = [
45
    'rand', 'crypto', 'SSL', 'tsafe', '__version__']