diff options
author | Marc Abramowitz <marc@marc-abramowitz.com> | 2013-11-11 22:45:42 +0000 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2014-02-22 12:40:25 -0800 |
commit | eb51036c9b8de72b53bcd2f0754c698d2ad40380 (patch) | |
tree | ded3d471c9c15b6b1a1401d3f41bf1164e775918 | |
parent | 5dc0db200952fe4ea65e4100f4e0c1a2bb79b9f2 (diff) | |
download | pycrypto-eb51036c9b8de72b53bcd2f0754c698d2ad40380.tar.gz |
Refactor 3 places handling fastmath ImportError
so that they call `Crypto.SelfTest.st_common.handle_fastmath_import_error`,
thereby eliminiating duplicate code.
-rw-r--r-- | lib/Crypto/SelfTest/PublicKey/test_DSA.py | 12 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/PublicKey/test_RSA.py | 12 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/Util/test_number.py | 12 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/st_common.py | 12 |
4 files changed, 18 insertions, 30 deletions
diff --git a/lib/Crypto/SelfTest/PublicKey/test_DSA.py b/lib/Crypto/SelfTest/PublicKey/test_DSA.py index 72b9e95..037e087 100644 --- a/lib/Crypto/SelfTest/PublicKey/test_DSA.py +++ b/lib/Crypto/SelfTest/PublicKey/test_DSA.py @@ -225,16 +225,8 @@ def get_tests(config={}): from Crypto.PublicKey import _fastmath tests += list_test_cases(DSAFastMathTest) except ImportError: - from distutils.sysconfig import get_config_var - import inspect - 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) + from Crypto.SelfTest.st_common import handle_fastmath_import_error + handle_fastmath_import_error() tests += list_test_cases(DSASlowMathTest) return tests diff --git a/lib/Crypto/SelfTest/PublicKey/test_RSA.py b/lib/Crypto/SelfTest/PublicKey/test_RSA.py index 15f2a4f..32bed88 100644 --- a/lib/Crypto/SelfTest/PublicKey/test_RSA.py +++ b/lib/Crypto/SelfTest/PublicKey/test_RSA.py @@ -461,16 +461,8 @@ def get_tests(config={}): from Crypto.PublicKey import _fastmath tests += list_test_cases(RSAFastMathTest) except ImportError: - from distutils.sysconfig import get_config_var - import inspect - 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) + from Crypto.SelfTest.st_common import handle_fastmath_import_error + handle_fastmath_import_error() if config.get('slow_tests',1): tests += list_test_cases(RSASlowMathTest) return tests diff --git a/lib/Crypto/SelfTest/Util/test_number.py b/lib/Crypto/SelfTest/Util/test_number.py index 834607b..709a774 100644 --- a/lib/Crypto/SelfTest/Util/test_number.py +++ b/lib/Crypto/SelfTest/Util/test_number.py @@ -325,16 +325,8 @@ def get_tests(config={}): from Crypto.PublicKey import _fastmath tests += list_test_cases(FastmathTests) except ImportError: - 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) + from Crypto.SelfTest.st_common import handle_fastmath_import_error + handle_fastmath_import_error() return tests if __name__ == '__main__': diff --git a/lib/Crypto/SelfTest/st_common.py b/lib/Crypto/SelfTest/st_common.py index c56eac5..627ace7 100644 --- a/lib/Crypto/SelfTest/st_common.py +++ b/lib/Crypto/SelfTest/st_common.py @@ -59,4 +59,16 @@ def b2a_hex(s): # For completeness 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) + # vim:set ts=4 sw=4 sts=4 expandtab: |