14adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao"""Fixer that changes input(...) into eval(input(...)).""" 24adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao# Author: Andre Roberge 34adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 44adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao# Local imports 54adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaofrom .. import fixer_base 64adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaofrom ..fixer_util import Call, Name 74adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaofrom .. import patcomp 84adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 94adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 104adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaocontext = patcomp.compile_pattern("power< 'eval' trailer< '(' any ')' > >") 114adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 124adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 134adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaoclass FixInput(fixer_base.BaseFix): 144adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao BM_compatible = True 154adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao PATTERN = """ 164adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao power< 'input' args=trailer< '(' [any] ')' > > 174adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao """ 184adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 194adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao def transform(self, node, results): 204adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao # If we're already wrapped in a eval() call, we're done. 214adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao if context.match(node.parent.parent): 224adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao return 234adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 244adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao new = node.clone() 254adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao new.prefix = u"" 264adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao return Call(Name(u"eval"), [new], prefix=node.prefix) 27