eric6/Utilities/ClassBrowsers/__init__.py

changeset 7400
e5d62581d002
parent 7360
9190402e4505
child 7637
c878e8255972
equal deleted inserted replaced
7399:7088860e4a00 7400:e5d62581d002
19 </ul> 19 </ul>
20 """ 20 """
21 21
22 22
23 import os 23 import os
24 import imp 24 import importlib
25 25
26 import Preferences 26 import Preferences
27 27
28 PY_SOURCE = imp.PY_SOURCE 28 PY_SOURCE = 1
29 PTL_SOURCE = 128 29 PTL_SOURCE = 128
30 RB_SOURCE = 129 30 RB_SOURCE = 129
31 IDL_SOURCE = 130 31 IDL_SOURCE = 130
32 JS_SOURCE = 131 32 JS_SOURCE = 131
33 PROTO_SOURCE = 132 33 PROTO_SOURCE = 132
152 pathname = os.path.join(p, name) 152 pathname = os.path.join(p, name)
153 if os.path.exists(pathname): 153 if os.path.exists(pathname):
154 return (open(pathname), pathname, (ext, 'r', PTL_SOURCE)) 154 return (open(pathname), pathname, (ext, 'r', PTL_SOURCE))
155 raise ImportError 155 raise ImportError
156 156
157 elif (
158 name.lower().endswith(
159 tuple(Preferences.getPython("PythonExtensions") +
160 Preferences.getPython("Python3Extensions"))) or
161 isPyFile
162 ):
163 for p in path: # search in path
164 pathname = os.path.join(p, name)
165 if os.path.exists(pathname):
166 return (open(pathname), pathname, (ext, 'r', PY_SOURCE))
167 raise ImportError
168
169 # standard Python module file
157 if name.lower().endswith('.py'): 170 if name.lower().endswith('.py'):
158 name = name[:-3] 171 name = name[:-3]
159 172
160 try: 173 spec = importlib.machinery.PathFinder.find_spec(name, path)
161 return imp.find_module(name, path) 174 if spec is None:
162 except ImportError:
163 if (
164 name.lower().endswith(
165 tuple(Preferences.getPython("PythonExtensions") +
166 Preferences.getPython("Python3Extensions"))) or
167 isPyFile
168 ):
169 for p in path: # search in path
170 pathname = os.path.join(p, name)
171 if os.path.exists(pathname):
172 return (open(pathname), pathname, (ext, 'r', PY_SOURCE))
173 raise ImportError 175 raise ImportError
174 except SyntaxError: 176 if isinstance(spec.loader, importlib.machinery.SourceFileLoader):
175 # re-raise as an import error 177 ext = os.path.splitext(spec.origin)[-1]
176 raise ImportError 178 return (open(spec.origin), spec.origin, (ext, 'r', PY_SOURCE))
179
180 raise ImportError

eric ide

mercurial