def refactor_with_2to3(source_text, fixer_names, filename=u''):
 from lib2to3.refactor import RefactoringTool
 fixers = [(u'lib2to3.fixes.fix_' + name) for name in fixer_names]
 tool = RefactoringTool(fixer_names=fixers, explicit=fixers)
 from lib2to3.pgen2 import tokenize as lib2to3_tokenize
 try:
  return unicode(tool.refactor_string(source_text, name=filename))
 except lib2to3_tokenize.TokenError:
  return source_text

def refactor_with_2to3 ( source_text , fixer_names , filename = u'' ) : from lib2to3 . refactor import RefactoringTool fixers = [ ( u'lib2to3.fixes.fix_' + name ) for name in fixer_names ] tool = RefactoringTool ( fixer_names = fixers , explicit = fixers ) from lib2to3 . pgen2 import tokenize as lib2to3_tokenize try : return unicode ( tool . refactor_string ( source_text , name = filename ) ) except lib2to3_tokenize . TokenError : return source_text
use lib2to3 to refactor the source .