flask/scripts/fix_ext_import.py
Keyan Pishdadian 0b2556f3ec Add lib2to3 fixer base code
Switching to using RedBaron instead of lib2to3, committing to save lib2to3 code in case using Baron is not successful.
2015-02-10 11:23:16 -05:00

20 lines
594 B
Python

from lib2to3.fixer_base import BaseFix
from lib2to3.fixer_util import Name, syms
class FixExtImport(BaseFix):
PATTERN = "fixnode='oldname'"
def transform(self, node, results):
fixnode = results['fixnode']
fixnode.replace(Name('newname', prefix=fixnode.prefix))
if node.type == syms.import_from and \
getattr(results['imp'], 'value', None) == 'flask.ext':
return 0
# TODO: Case 2
# CASE 1 - from flask.ext.foo import bam --> from flask_foo import bam
# CASE 2 - from flask.ext import foo --> import flask_foo as foo