diff --git a/pysmi/borrower/pyfile.py b/pysmi/borrower/pyfile.py index ba88d68..eae75b0 100644 --- a/pysmi/borrower/pyfile.py +++ b/pysmi/borrower/pyfile.py @@ -7,12 +7,17 @@ try: import importlib - SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES + try: + SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES + + except Exception: + raise ImportError() except ImportError: import imp - SOURCE_SUFFIXES = [imp.PY_SOURCE] + SOURCE_SUFFIXES = [s[0] for s in imp.get_suffixes() + if s[2] == imp.PY_SOURCE] from pysmi.borrower.base import AbstractBorrower diff --git a/pysmi/searcher/pyfile.py b/pysmi/searcher/pyfile.py index 00fbf62..1199cf7 100644 --- a/pysmi/searcher/pyfile.py +++ b/pysmi/searcher/pyfile.py @@ -11,14 +11,20 @@ try: import importlib - SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES - BYTECODE_SUFFIXES = importlib.machinery.BYTECODE_SUFFIXES + try: + SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES + BYTECODE_SUFFIXES = importlib.machinery.BYTECODE_SUFFIXES + + except Exception: + raise ImportError() except ImportError: import imp - SOURCE_SUFFIXES = [imp.PY_SOURCE] - BYTECODE_SUFFIXES = [imp.PY_COMPILED] + SOURCE_SUFFIXES = [s[0] for s in imp.get_suffixes() + if s[2] == imp.PY_SOURCE] + BYTECODE_SUFFIXES = [s[0] for s in imp.get_suffixes() + if s[2] == imp.PY_COMPILED] from pysmi.searcher.base import AbstractSearcher from pysmi.compat import decode diff --git a/pysmi/searcher/pypackage.py b/pysmi/searcher/pypackage.py index 9065447..597a209 100644 --- a/pysmi/searcher/pypackage.py +++ b/pysmi/searcher/pypackage.py @@ -10,16 +10,22 @@ try: import importlib - PY_MAGIC_NUMBER = importlib.util.MAGIC_NUMBER - SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES - BYTECODE_SUFFIXES = importlib.machinery.BYTECODE_SUFFIXES + try: + PY_MAGIC_NUMBER = importlib.util.MAGIC_NUMBER + SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES + BYTECODE_SUFFIXES = importlib.machinery.BYTECODE_SUFFIXES + + except Exception: + raise ImportError() except ImportError: import imp PY_MAGIC_NUMBER = imp.get_magic() - SOURCE_SUFFIXES = [imp.PY_SOURCE] - BYTECODE_SUFFIXES = [imp.PY_COMPILED] + SOURCE_SUFFIXES = [s[0] for s in imp.get_suffixes() + if s[2] == imp.PY_SOURCE] + BYTECODE_SUFFIXES = [s[0] for s in imp.get_suffixes() + if s[2] == imp.PY_COMPILED] from pysmi.searcher.base import AbstractSearcher from pysmi.searcher.pyfile import PyFileSearcher diff --git a/pysmi/writer/pyfile.py b/pysmi/writer/pyfile.py index 672a338..3627939 100644 --- a/pysmi/writer/pyfile.py +++ b/pysmi/writer/pyfile.py @@ -8,15 +8,21 @@ import sys import tempfile import py_compile + try: import importlib - SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES + try: + SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES + + except Exception: + raise ImportError() except ImportError: import imp - SOURCE_SUFFIXES = [imp.PY_SOURCE] + SOURCE_SUFFIXES = [s[0] for s in imp.get_suffixes() + if s[2] == imp.PY_SOURCE] from pysmi.writer.base import AbstractWriter from pysmi.compat import encode, decode