~ubuntu-branches/ubuntu/natty/pycryptopp/natty

« back to all changes in this revision

Viewing changes to pycryptopp/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Zooko O'Whielacronx
  • Date: 2009-06-22 22:20:50 UTC
  • Revision ID: james.westby@ubuntu.com-20090622222050-hbqmn50dt2kvoz5o
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
pycryptopp - Python wrappers for Crypto++
 
3
"""
 
4
 
 
5
__version__ = "unknown"
 
6
try:
 
7
    from _version import __version__
 
8
except ImportError:
 
9
    # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
 
10
    # come with a _version.py, so we don't know what our version is. This should
 
11
    # not happen very often.
 
12
    pass
 
13
 
 
14
# we import our glue .so here, and then other modules use the copy in
 
15
# sys.modules. We wrap the import with RTLD_GLOBAL to make the C++ symbols in
 
16
# our _pycryptopp.so glue match the symbols defined in libcrypto++.so . On
 
17
# windows, which has RTLD_GLOBAL but not sys.getdlopenflags), we just import
 
18
# it normally, because windows is basically always in RTLD_GLOBAL mode.
 
19
 
 
20
import sys
 
21
 
 
22
use_RTLD_GLOBAL = hasattr(sys, "getdlopenflags")
 
23
if use_RTLD_GLOBAL:
 
24
    try:
 
25
        from ctypes import RTLD_GLOBAL as RTLD_GLOBAL_FROM_CTYPES
 
26
        RTLD_GLOBAL = RTLD_GLOBAL_FROM_CTYPES # hack to hush pyflakes
 
27
        del RTLD_GLOBAL_FROM_CTYPES
 
28
    except ImportError:
 
29
        # ctypes was added in Python 2.5 -- we still support Python 2.4, which
 
30
        # had dl instead
 
31
        from dl import RTLD_GLOBAL as RTLD_GLOBAL_FROM_DL
 
32
        RTLD_GLOBAL = RTLD_GLOBAL_FROM_DL
 
33
        del RTLD_GLOBAL_FROM_DL
 
34
    flags = sys.getdlopenflags()
 
35
 
 
36
try:
 
37
    if use_RTLD_GLOBAL:
 
38
        sys.setdlopenflags(flags|RTLD_GLOBAL)
 
39
 
 
40
    import _pycryptopp # all that work for one little import
 
41
 
 
42
finally:
 
43
    if use_RTLD_GLOBAL:
 
44
        sys.setdlopenflags(flags)
 
45
        del flags, RTLD_GLOBAL
 
46
 
 
47
 
 
48
def _import_my_names(thismodule, prefix):
 
49
    for name in dir(_pycryptopp):
 
50
        if name.startswith(prefix):
 
51
            myname = name[len(prefix):]
 
52
            thismodule[myname] = getattr(_pycryptopp, name)
 
53
 
 
54
import publickey, hash, cipher
 
55
 
 
56
quiet_pyflakes=[__version__, publickey, hash, cipher, _pycryptopp]
 
57
del sys, quiet_pyflakes