diff options
author | Brett Cannon <brett@python.org> | 2013-06-07 17:18:36 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-06-07 17:18:36 (GMT) |
commit | abb18af38fdbcce9971960edd5ee5ad0b225055a (patch) | |
tree | 54fa560735bde9ab6cdc2dc54a3635be1201d12c /Lib/idlelib/EditorWindow.py | |
parent | a33e11e436de15baa1f0feb9d2d60d28f137eb3d (diff) | |
parent | 50793b44382e8d2bdd3a89a0c1ecd8eb97093e22 (diff) | |
download | cpython-abb18af38fdbcce9971960edd5ee5ad0b225055a.zip cpython-abb18af38fdbcce9971960edd5ee5ad0b225055a.tar.gz cpython-abb18af38fdbcce9971960edd5ee5ad0b225055a.tar.bz2 |
merge w/ 3.3 for issue #18055
Diffstat (limited to 'Lib/idlelib/EditorWindow.py')
-rw-r--r-- | Lib/idlelib/EditorWindow.py | 57 |
1 files changed, 19 insertions, 38 deletions
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index 6bb5301..bdfeb95 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -1,5 +1,5 @@ -import imp import importlib +import importlib.abc import os import re import string @@ -35,34 +35,6 @@ def _sphinx_version(): release += '%s%s' % (level[0], serial) return release -def _find_module(fullname, path=None): - """Version of imp.find_module() that handles hierarchical module names""" - - file = None - for tgt in fullname.split('.'): - if file is not None: - file.close() # close intermediate files - (file, filename, descr) = imp.find_module(tgt, path) - if descr[2] == imp.PY_SOURCE: - break # find but not load the source file - module = imp.load_module(tgt, file, filename, descr) - try: - path = module.__path__ - except AttributeError: - raise ImportError('No source for module ' + module.__name__) - if descr[2] != imp.PY_SOURCE: - # If all of the above fails and didn't raise an exception,fallback - # to a straight import which can find __init__.py in a package. - m = __import__(fullname) - try: - filename = m.__file__ - except AttributeError: - pass - else: - file = None - descr = os.path.splitext(filename)[1], None, imp.PY_SOURCE - return file, filename, descr - class HelpDialog(object): @@ -687,20 +659,29 @@ class EditorWindow(object): return # XXX Ought to insert current file's directory in front of path try: - (f, file, (suffix, mode, type)) = _find_module(name) - except (NameError, ImportError) as msg: + loader = importlib.find_loader(name) + except (ValueError, ImportError) as msg: tkMessageBox.showerror("Import error", str(msg), parent=self.text) return - if type != imp.PY_SOURCE: - tkMessageBox.showerror("Unsupported type", - "%s is not a source module" % name, parent=self.text) + if loader is None: + tkMessageBox.showerror("Import error", "module not found", + parent=self.text) + return + if not isinstance(loader, importlib.abc.SourceLoader): + tkMessageBox.showerror("Import error", "not a source-based module", + parent=self.text) + return + try: + file_path = loader.get_filename(name) + except AttributeError: + tkMessageBox.showerror("Import error", + "loader does not support get_filename", + parent=self.text) return - if f: - f.close() if self.flist: - self.flist.open(file) + self.flist.open(file_path) else: - self.io.loadfile(file) + self.io.loadfile(file_path) def open_class_browser(self, event=None): filename = self.io.filename |