PageRenderTime 243ms CodeModel.GetById 100ms app.highlight 2ms RepoModel.GetById 139ms app.codeStats 0ms

/Lib/lib2to3/fixes/fix_xreadlines.py

http://unladen-swallow.googlecode.com/
Python | 24 lines | 24 code | 0 blank | 0 comment | 2 complexity | ade2c0b61ba9f8effa9df543a2fbdc4a MD5 | raw file
 1"""Fix "for x in f.xreadlines()" -> "for x in f".
 2
 3This fixer will also convert g(f.xreadlines) into g(f.__iter__)."""
 4# Author: Collin Winter
 5
 6# Local imports
 7from .. import fixer_base
 8from ..fixer_util import Name
 9
10
11class FixXreadlines(fixer_base.BaseFix):
12    PATTERN = """
13    power< call=any+ trailer< '.' 'xreadlines' > trailer< '(' ')' > >
14    |
15    power< any+ trailer< '.' no_call='xreadlines' > >
16    """
17
18    def transform(self, node, results):
19        no_call = results.get("no_call")
20
21        if no_call:
22            no_call.replace(Name("__iter__", prefix=no_call.get_prefix()))
23        else:
24            node.replace([x.clone() for x in results["call"]])