ó
	Q˜[c           @   s   d  Z  d d l m Z d d l m Z d d l m Z d d l m	 Z	 m
 Z
 m Z d Z d e j f d „  ƒ  YZ d	 „  Z d
 „  Z d „  Z d S(   s  
Based on fix_next.py by Collin Winter.

Replaces it.next() -> next(it), per PEP 3114.

Unlike fix_next.py, this fixer doesn't replace the name of a next method with __next__,
which would break Python 2 compatibility without further help from fixers in
stage 2.
iÿÿÿÿ(   t   token(   t   python_symbols(   t
   fixer_base(   t   Namet   Callt   find_bindings;   Calls to builtin next() possibly shadowed by global bindingt   FixNextCallc           B   s,   e  Z e Z d  Z d Z d „  Z d „  Z RS(   sÓ   
    power< base=any+ trailer< '.' attr='next' > trailer< '(' ')' > >
    |
    power< head=any+ trailer< '.' attr='next' > not trailer< '(' ')' > >
    |
    global=global_stmt< 'global' any* 'next' any* >
    t   prec         C   sW   t  t |  ƒ j | | ƒ t d | ƒ } | rJ |  j | t ƒ t |  _ n	 t |  _ d  S(   Nt   next(	   t   superR   t
   start_treeR   t   warningt   bind_warningt   Truet   shadowed_nextt   False(   t   selft   treet   filenamet   n(    (    s>   lib/python2.7/site-packages/libfuturize/fixes/fix_next_call.pyR
       s    c         C   s>  | s t  ‚ | j d ƒ } | j d ƒ } | j d ƒ } | rŸ |  j rK q:g  | D] } | j ƒ  ^ qR } d | d _ | j t t d d | j ƒ| ƒ ƒ n› | r¨ n’ | rt | ƒ r:| d } d j	 g  | D] } t
 | ƒ ^ qÑ ƒ j ƒ  d	 k r|  j | t ƒ n  d  Sn( d
 | k r:|  j | t ƒ t |  _ n  d  S(   Nt   baset   attrt   namet    i    R   t   prefixt   headt   __builtin__t   global(   t   AssertionErrort   getR   t   cloneR   t   replaceR   R   t   is_assign_targett   joint   strt   stripR   R   R   (   R   t   nodet   resultsR   R   R   R   R   (    (    s>   lib/python2.7/site-packages/libfuturize/fixes/fix_next_call.pyt	   transform*   s*    	(
4(   t   __name__t
   __module__R   t   BM_compatiblet   PATTERNt   orderR
   R&   (    (    (    s>   lib/python2.7/site-packages/libfuturize/fixes/fix_next_call.pyR      s
   	
c         C   s]   t  |  ƒ } | d  k r t Sx: | j D]/ } | j t j k rB t St | |  ƒ r& t Sq& Wt S(   N(	   t   find_assignt   NoneR   t   childrent   typeR    t   EQUALt
   is_subtreeR   (   R$   t   assignt   child(    (    s>   lib/python2.7/site-packages/libfuturize/fixes/fix_next_call.pyR    R   s    c         C   sH   |  j  t j k r |  S|  j  t j k s7 |  j d  k r; d  St |  j ƒ S(   N(   R/   t   symst	   expr_stmtt   simple_stmtt   parentR-   R,   (   R$   (    (    s>   lib/python2.7/site-packages/libfuturize/fixes/fix_next_call.pyR,   ^   s
    !c            s-   |  ˆ  k r t  St ‡  f d †  |  j Dƒ ƒ S(   Nc         3   s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   R1   (   t   .0t   c(   R$   (    s>   lib/python2.7/site-packages/libfuturize/fixes/fix_next_call.pys	   <genexpr>h   s    (   R   t   anyR.   (   t   rootR$   (    (   R$   s>   lib/python2.7/site-packages/libfuturize/fixes/fix_next_call.pyR1   e   s    N(   t   __doc__t   lib2to3.pgen2R    t   lib2to3.pygramR   R4   t   lib2to3R   t   lib2to3.fixer_utilR   R   R   R   t   BaseFixR   R    R,   R1   (    (    (    s>   lib/python2.7/site-packages/libfuturize/fixes/fix_next_call.pyt   <module>	   s   >		