Merged revisions 61825 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61825 | martin.v.loewis | 2008-03-24 01:46:53 +0100 (Mo, 24 Mär 2008) | 17 lines
Merged revisions 61724-61824 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61730 | martin.v.loewis | 2008-03-22 02:20:58 +0100 (Sa, 22 Mär 2008) | 2 lines
More explicit relative imports.
........
r61755 | david.wolever | 2008-03-22 21:33:52 +0100 (Sa, 22 Mär 2008) | 1 line
Fixing #2446 -- 2to3 now translates 'import foo' to 'from . import foo'
........
r61824 | david.wolever | 2008-03-24 01:30:24 +0100 (Mo, 24 Mär 2008) | 3 lines
Fixed a bug where 'from itertools import izip' would return 'from itertools import'
........
................
diff --git a/Lib/lib2to3/fixes/util.py b/Lib/lib2to3/fixes/util.py
index 806bf28..b48aeb3 100644
--- a/Lib/lib2to3/fixes/util.py
+++ b/Lib/lib2to3/fixes/util.py
@@ -108,6 +108,26 @@
inner,
Leaf(token.RBRACE, "]")])
+def FromImport(package_name, name_leafs):
+ """ Return an import statement in the form:
+ from package import name_leafs"""
+ # XXX: May not handle dotted imports properly (eg, package_name='foo.bar')
+ assert package_name == '.' or '.' not in package.name, "FromImport has "\
+ "not been tested with dotted package names -- use at your own "\
+ "peril!"
+
+ for leaf in name_leafs:
+ # Pull the leaves out of their old tree
+ leaf.remove()
+
+ children = [Leaf(token.NAME, 'from'),
+ Leaf(token.NAME, package_name, prefix=" "),
+ Leaf(token.NAME, 'import', prefix=" "),
+ Node(syms.import_as_names, name_leafs)]
+ imp = Node(syms.import_from, children)
+ return imp
+
+
###########################################################
### Determine whether a node represents a given literal
###########################################################