From 87280f4419c8befffcdd153468aba4582493dcc4 Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sat, 22 Feb 2014 13:02:07 -0800 Subject: Fix handle_fastmath_import_error (broken due to incorrect path in the previous commit) Tested on py21-py33 by force-uninstalling libgmp10 after building. --- lib/Crypto/SelfTest/st_common.py | 21 +++++++++++---------- 1 file 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: -- cgit v1.2.1