~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Lib/lib2to3/fixes/fix_input.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Fixer that changes input(...) into eval(input(...))."""
 
2
# Author: Andre Roberge
 
3
 
 
4
# Local imports
 
5
from .. import fixer_base
 
6
from ..fixer_util import Call, Name
 
7
from .. import patcomp
 
8
 
 
9
 
 
10
context = patcomp.compile_pattern("power< 'eval' trailer< '(' any ')' > >")
 
11
 
 
12
 
 
13
class FixInput(fixer_base.BaseFix):
 
14
    BM_compatible = True
 
15
    PATTERN = """
 
16
              power< 'input' args=trailer< '(' [any] ')' > >
 
17
              """
 
18
 
 
19
    def transform(self, node, results):
 
20
        # If we're already wrapped in a eval() call, we're done.
 
21
        if context.match(node.parent.parent):
 
22
            return
 
23
 
 
24
        new = node.clone()
 
25
        new.prefix = ""
 
26
        return Call(Name("eval"), [new], prefix=node.prefix)