ó
è¾bc           @   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.   Fixer for it.next() -> next(it), per PEP 3114.i   (   t   token(   t   python_symbols(   t
   fixer_base(   t   Namet   Callt   find_bindings;   Calls to builtin next() possibly shadowed by global bindingt   FixNextc           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< '(' ')' > >
    |
    classdef< 'class' any+ ':'
              suite< any*
                     funcdef< 'def'
                              name='next'
                              parameters< '(' NAME ')' > any+ >
                     any* > >
    |
    global=global_stmt< 'global' any* 'next' any* >
    t   prec         C   sW   t  t |  ƒ j | | ƒ t d | ƒ } | rJ |  j | t ƒ t |  _ n	 t |  _ d  S(   Nu   next(	   t   superR   t
   start_treeR   t   warningt   bind_warningt   Truet   shadowed_nextt   False(   t   selft   treet   filenamet   n(    (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_next.pyR	   $   s    c         C   s  | s t  ‚ | j d ƒ } | j d ƒ } | j d ƒ } | r» |  j rg | j t d d | j ƒƒ q‹g  | D] } | j ƒ  ^ qn } d | d _ | j t t d d | j ƒ| ƒ ƒ nÐ | ræ t d d | j ƒ} | j | ƒ n¥ | rct | ƒ rM| d	 } d
 j	 g  | D] } t
 | ƒ ^ qƒ j ƒ  d k rI|  j | t ƒ n  d  S| j t d ƒ ƒ n( d | k r‹|  j | t ƒ t |  _ n  d  S(   Nt   baset   attrt   nameu   __next__t   prefixu    i    u   nextt   headt    u   __builtin__t   global(   t   AssertionErrort   getR   t   replaceR   R   t   cloneR   t   is_assign_targett   joint   strt   stripR
   R   R   (   R   t   nodet   resultsR   R   R   R   R   (    (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_next.pyt	   transform.   s.    	(
4(   t   __name__t
   __module__R   t   BM_compatiblet   PATTERNt   orderR	   R$   (    (    (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_next.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,   /usr/lib/python2.7/lib2to3/fixes/fix_next.pyR   Q   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,   /usr/lib/python2.7/lib2to3/fixes/fix_next.pyR*   ]   s
    !c            s-   |  ˆ  k r t  St ‡  f d †  |  j Dƒ ƒ S(   Nc         3   s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   R/   (   t   .0t   c(   R"   (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_next.pys	   <genexpr>g   s    (   R   t   anyR,   (   t   rootR"   (    (   R"   s,   /usr/lib/python2.7/lib2to3/fixes/fix_next.pyR/   d   s    N(   t   __doc__t   pgen2R    t   pygramR   R2   R   R   t
   fixer_utilR   R   R   R   t   BaseFixR   R   R*   R/   (    (    (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_next.pyt   <module>   s   @		