summaryrefslogtreecommitdiffstats
path: root/Tools/idle
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-09-08 03:42:01 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-09-08 03:42:01 (GMT)
commitb2c729fe2758d13ce4a5affdc67c3f7573edbc48 (patch)
tree92bcc28312e8c13da69e8d8de3d95b334981d432 /Tools/idle
parentd750036b20be5f8ce0a356fe625e8ade3a6c071a (diff)
downloadcpython-b2c729fe2758d13ce4a5affdc67c3f7573edbc48.zip
cpython-b2c729fe2758d13ce4a5affdc67c3f7573edbc48.tar.gz
cpython-b2c729fe2758d13ce4a5affdc67c3f7573edbc48.tar.bz2
Extended IDLE's open module menu item to handle hierarchical module names.
Will look at doing something similar in import.c so that the effort won't have to be repeated elsewhere. Closes SF patch 600152.
Diffstat (limited to 'Tools/idle')
-rw-r--r--Tools/idle/EditorWindow.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/Tools/idle/EditorWindow.py b/Tools/idle/EditorWindow.py
index 9535261..e8b63ff 100644
--- a/Tools/idle/EditorWindow.py
+++ b/Tools/idle/EditorWindow.py
@@ -81,6 +81,20 @@ An Integrated DeveLopment Environment for Python
by Guido van Rossum
""" % idlever.IDLE_VERSION
+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)
+ path = module.__path__
+ return file, filename, descr
+
class EditorWindow:
from Percolator import Percolator
@@ -340,10 +354,9 @@ class EditorWindow:
name = string.strip(name)
if not name:
return
- # XXX Ought to support package syntax
# XXX Ought to insert current file's directory in front of path
try:
- (f, file, (suffix, mode, type)) = imp.find_module(name)
+ (f, file, (suffix, mode, type)) = _find_module(name)
except (NameError, ImportError), msg:
tkMessageBox.showerror("Import error", str(msg), parent=self.text)
return