ó
è¾bc           @   s·   d  Z  d d l m 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
 m Z m Z m Z d d l m Z e j e d g ƒ BZ d	 e j f d
 „  ƒ  YZ d S(   sj  Fixer for dict methods.

d.keys() -> list(d.keys())
d.items() -> list(d.items())
d.values() -> list(d.values())

d.iterkeys() -> iter(d.keys())
d.iteritems() -> iter(d.items())
d.itervalues() -> iter(d.values())

d.viewkeys() -> d.keys()
d.viewitems() -> d.items()
d.viewvalues() -> d.values()

Except in certain very specific contexts: the iter() can be dropped
when the context is list(), sorted(), iter() or for...in; the list()
can be dropped when the context is list() or sorted() (but not iter()
or for...in!). Special contexts that apply to both: list(), sorted(), tuple()
set(), any(), all(), sum().

Note: iter(d.keys()) could be written as iter(d) but since the
original d.iterkeys() was also redundant we don't fix this.  And there
are (rare) contexts where it makes a difference (e.g. when passing it
as an argument to a function that introspects the argument).
i   (   t   pytree(   t   patcomp(   t   token(   t
   fixer_base(   t   Namet   Callt   LParent   RParent   ArgListt   Dot(   t
   fixer_utilt   itert   FixDictc           B   sP   e  Z e Z d  Z d „  Z d Z e j e ƒ Z	 d Z
 e j e
 ƒ Z d „  Z RS(   s  
    power< head=any+
         trailer< '.' method=('keys'|'items'|'values'|
                              'iterkeys'|'iteritems'|'itervalues'|
                              'viewkeys'|'viewitems'|'viewvalues') >
         parens=trailer< '(' ')' >
         tail=any*
    >
    c         C   s§  | d } | d d } | d } |  j  } | j } | j d ƒ } | j d ƒ }	 | s^ |	 rk | d } n  | d k s‰ t t | ƒ ƒ ‚ g  | D] }
 |
 j ƒ  ^ q } g  | D] }
 |
 j ƒ  ^ q¯ } | oÝ |  j | | ƒ } | t j | j	 t
 ƒ  t | d | j ƒg ƒ | d j ƒ  g } t j | j | ƒ } | p?|	 srd | _ t t | r]d n d ƒ | g ƒ } n  | r—t j | j | g | ƒ } n  | j | _ | S(   Nt   headt   methodi    t   tailu   iteru   viewi   u   keysu   itemsu   valuest   prefixt   parensu    u   list(   u   keysu   itemsu   values(   t   symst   valuet
   startswitht   AssertionErrort   reprt   clonet   in_special_contextR    t   Nodet   trailerR	   R   R   t   powerR   (   t   selft   nodet   resultsR   R   R   R   t   method_namet   isitert   isviewt   nt   specialt   argst   new(    (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_dict.pyt	   transform7   s4    

				's3   power< func=NAME trailer< '(' node=any ')' > any* >sm   for_stmt< 'for' any 'in' node=any ':' any* >
            | comp_for< 'for' any 'in' node=any any* >
         c         C   s´   | j  d  k r t Si  } | j  j  d  k	 r„ |  j j | j  j  | ƒ r„ | d | k r„ | rm | d j t k S| d j t j k Sn  | sŽ t S|  j	 j | j  | ƒ o³ | d | k S(   NR   t   func(
   t   parentt   Nonet   Falset   p1t   matchR   t   iter_exemptR
   t   consuming_callst   p2(   R   R   R    R   (    (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_dict.pyR   [   s    (   t   __name__t
   __module__t   Truet   BM_compatiblet   PATTERNR&   t   P1R   t   compile_patternR+   t   P2R/   R   (    (    (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_dict.pyR   *   s   
	N(   t   __doc__t    R    R   t   pgen2R   R   R
   R   R   R   R   R   R	   R.   t   setR-   t   BaseFixR   (    (    (    s,   /usr/lib/python2.7/lib2to3/fixes/fix_dict.pyt   <module>   s   .