summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2014-02-22 13:02:07 -0800
committerDwayne Litzenberger <dlitz@dlitz.net>2014-02-22 13:08:45 -0800
commit87280f4419c8befffcdd153468aba4582493dcc4 (patch)
tree7e3069412b1fee27503ff8d102250ffb60c3fd48
parenteb51036c9b8de72b53bcd2f0754c698d2ad40380 (diff)
downloadpycrypto-87280f4419c8befffcdd153468aba4582493dcc4.tar.gz
Fix handle_fastmath_import_error (broken due to incorrect path in the previous commit)
Tested on py21-py33 by force-uninstalling libgmp10 after building.
-rw-r--r--lib/Crypto/SelfTest/st_common.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/Crypto/SelfTest/st_common.py b/lib/Crypto/SelfTest/st_common.py
index 627ace7..e0e206a 100644
--- a/lib/Crypto/SelfTest/st_common.py
+++ b/lib/Crypto/SelfTest/st_common.py
@@ -60,15 +60,16 @@ def b2a_hex(s):
return binascii.b2a_hex(s)
def handle_fastmath_import_error():
- from distutils.sysconfig import get_config_var
- import inspect, os.path
- ext_suffix = get_config_var("EXT_SUFFIX") or get_config_var("SO")
- _fm_path = os.path.normpath(os.path.dirname(os.path.abspath(
- inspect.getfile(inspect.currentframe())))
- +"/../../PublicKey/_fastmath"+ext_suffix)
- if os.path.exists(_fm_path):
- raise ImportError("While the _fastmath module exists, importing "+
- "it failed. This may point to the gmp or mpir shared library "+
- "not being in the path. _fastmath was found at "+_fm_path)
+ import Crypto.PublicKey
+ import imp
+ try:
+ file, pathname, description = imp.find_module("_fastmath", Crypto.PublicKey.__path__)
+ except ImportError:
+ sys.stderr.write("SelfTest: warning: not testing _fastmath module (not available)\n")
+ else:
+ file.close()
+ raise ImportError("While the _fastmath module exists, importing "
+ "it failed. This may point to the gmp or mpir shared library "
+ "not being in the path. _fastmath was found at %s" % (pathname,))
# vim:set ts=4 sw=4 sts=4 expandtab: