eric6/Utilities/ClassBrowsers/__init__.py

changeset 7400
e5d62581d002
parent 7360
9190402e4505
child 7637
c878e8255972
--- a/eric6/Utilities/ClassBrowsers/__init__.py	Fri Feb 07 18:49:32 2020 +0100
+++ b/eric6/Utilities/ClassBrowsers/__init__.py	Sat Feb 08 16:47:20 2020 +0100
@@ -21,11 +21,11 @@
 
 
 import os
-import imp
+import importlib
 
 import Preferences
 
-PY_SOURCE = imp.PY_SOURCE
+PY_SOURCE = 1
 PTL_SOURCE = 128
 RB_SOURCE = 129
 IDL_SOURCE = 130
@@ -154,23 +154,27 @@
                 return (open(pathname), pathname, (ext, 'r', PTL_SOURCE))
         raise ImportError
     
+    elif (
+        name.lower().endswith(
+            tuple(Preferences.getPython("PythonExtensions") +
+                  Preferences.getPython("Python3Extensions"))) or
+        isPyFile
+    ):
+        for p in path:      # search in path
+            pathname = os.path.join(p, name)
+            if os.path.exists(pathname):
+                return (open(pathname), pathname, (ext, 'r', PY_SOURCE))
+    raise ImportError
+    
+    # standard Python module file
     if name.lower().endswith('.py'):
         name = name[:-3]
     
-    try:
-        return imp.find_module(name, path)
-    except ImportError:
-        if (
-            name.lower().endswith(
-                tuple(Preferences.getPython("PythonExtensions") +
-                      Preferences.getPython("Python3Extensions"))) or
-            isPyFile
-        ):
-            for p in path:      # search in path
-                pathname = os.path.join(p, name)
-                if os.path.exists(pathname):
-                    return (open(pathname), pathname, (ext, 'r', PY_SOURCE))
+    spec = importlib.machinery.PathFinder.find_spec(name, path)
+    if spec is None:
         raise ImportError
-    except SyntaxError:
-        # re-raise as an import error
-        raise ImportError
+    if isinstance(spec.loader, importlib.machinery.SourceFileLoader):
+        ext = os.path.splitext(spec.origin)[-1]
+        return (open(spec.origin), spec.origin, (ext, 'r', PY_SOURCE))
+    
+    raise ImportError

eric ide

mercurial