10a8c90248264a8b26970b4473770bcc3df8515fJosh Gao"""Fixer that changes input(...) into eval(input(...)).""" 20a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Author: Andre Roberge 30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 40a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Local imports 50a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom .. import fixer_base 60a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom ..fixer_util import Call, Name 70a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom .. import patcomp 80a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 90a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 100a8c90248264a8b26970b4473770bcc3df8515fJosh Gaocontext = patcomp.compile_pattern("power< 'eval' trailer< '(' any ')' > >") 110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 130a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass FixInput(fixer_base.BaseFix): 140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao BM_compatible = True 150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao PATTERN = """ 160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao power< 'input' args=trailer< '(' [any] ')' > > 170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao """ 180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def transform(self, node, results): 200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # If we're already wrapped in a eval() call, we're done. 210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if context.match(node.parent.parent): 220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return 230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao new = node.clone() 250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao new.prefix = u"" 260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Call(Name(u"eval"), [new], prefix=node.prefix) 27