Permalink
Browse files

Make it work with python3.2

  • Loading branch information...
1 parent 54ba6e9 commit 78d70f87423774a01e02b3cded446aeb7b0a2578 @bdarnell committed Feb 24, 2011
Showing with 8 additions and 14 deletions.
  1. +8 −14 auto2to3.py
View
@@ -15,18 +15,12 @@
import tempfile
import lib2to3
-from lib2to3.refactor import RefactoringTool
+from lib2to3.refactor import RefactoringTool, get_fixers_from_package
sys.path.append(os.path.dirname(lib2to3.__file__))
-class DummyOptions:
- fix = []
- def __getattr__(self, name):
- return None
-
-opt = DummyOptions()
-
-rt = RefactoringTool(opt)
+fixes = get_fixers_from_package('lib2to3.fixes')
+rt = RefactoringTool(fixes)
PACKAGES = []
@@ -51,15 +45,15 @@ def find_module(self, fullname, path=None):
file.seek(0)
if 'python2' in line1 or 'python2' in line2:
try:
- tree = rt.driver.parse_stream(file)
+ tree = rt.refactor_string(file.read(), filename)
except Exception as err:
raise ImportError("2to3 couldn't convert %r" % filename)
finally:
file.close()
- if rt.refactor_tree(tree, filename):
- file = tempfile.TemporaryFile()
- file.write(str(tree).encode('utf8'))
- file.seek(0)
+ filename = '/tmp/auto2to3-%s.py' % fullname
+ file = open(filename, 'rb+')
+ file.write(str(tree).encode('utf8'))
+ file.seek(0)
return ImpLoader(fullname, file, filename, etc)

0 comments on commit 78d70f8

Please sign in to comment.