;
Ðâ"Ic                @   sX  d  Z  d d l m Z d d l m Z m Z d d l m Z d d l	 m
 Z
 d „  Z d „  Z d „  Z d	 „  Z d0 d
 „ Z d „  Z d „  Z d „  Z e ƒ  e ƒ  d „ Z d0 d0 d „ Z d „  Z d „  Z d0 d „ Z d „  Z d0 d „ Z d0 d „ Z d „  Z d „  Z d „  Z y
 e Z Wn e  k
 o d „  Z Yn Xy
 e! Z! Wn$ e  k
 o d d l" m# Z! Yn Xy
 e$ Z$ Wn e  k
 o d „  Z$ Yn Xe! d d d d  d! d" d# d$ d% g	 ƒ Z% d& „  Z& d' a' d( a( d) a) d1 a+ d* „  Z, d+ „  Z- d, „  Z. e! e j/ e j0 g ƒ Z1 d0 d- „ Z2 e! e j0 e j/ e j3 g ƒ Z4 d. „  Z5 d0 d/ „ Z6 d0 S(2   u1   Utility functions, node construction macros, etc.i   (   u   token(   u   Leafu   Node(   u   python_symbols(   u   patcompc             C   s%   t  t j |  t t j d ƒ | g ƒ S(   Nu   =(   u   Nodeu   symsu   argumentu   Leafu   tokenu   EQUAL(   u   keywordu   value(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu
   KeywordArg   s    	c               C   s   t  t j d ƒ S(   Nu   ((   u   Leafu   tokenu   LPAR(    (    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   LParen   s    c               C   s   t  t j d ƒ S(   Nu   )(   u   Leafu   tokenu   RPAR(    (    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   RParen   s    c             C   st   t  |  t ƒ p |  g }  n t  | t ƒ p | j d ƒ | g } n t t j |  t t j d d d ƒg | ƒ S(   u   Build an assignment statementu    u   =u   prefix(	   u
   isinstanceu   listu
   set_prefixu   Nodeu   symsu   atomu   Leafu   tokenu   EQUAL(   u   targetu   source(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   Assign   s    	c             C   s   t  t j |  d | ƒS(   u   Return a NAME leafu   prefix(   u   Leafu   tokenu   NAME(   u   nameu   prefix(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   Name$   s    c             C   s   |  t  t j t ƒ  | g ƒ g S(   u   A node tuple for obj.attr(   u   Nodeu   symsu   traileru   Dot(   u   obju   attr(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   Attr(   s    c               C   s   t  t j d ƒ S(   u   A comma leafu   ,(   u   Leafu   tokenu   COMMA(    (    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   Comma,   s    c               C   s   t  t j d ƒ S(   u   A period (.) leafu   .(   u   Leafu   tokenu   DOT(    (    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   Dot0   s    c             C   sO   t  t j | j ƒ  | j ƒ  g ƒ } |  o  | j d t  t j |  ƒ ƒ n | S(   u-   A parenthesised argument list, used by Call()i   (   u   Nodeu   symsu   traileru   cloneu   insert_childu   arglist(   u   argsu   lparenu   rparenu   node(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   ArgList4   s    $ c             C   s@   t  t j |  t | ƒ g ƒ } | d k	 o | j | ƒ n | S(   u   A function callN(   u   Nodeu   symsu   poweru   ArgListu   Noneu
   set_prefix(   u	   func_nameu   argsu   prefixu   node(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   Call;   s    c               C   s   t  t j d ƒ S(   u   A newline literalu   
(   u   Leafu   tokenu   NEWLINE(    (    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   NewlineB   s    c               C   s   t  t j d ƒ S(   u   A blank lineu    (   u   Leafu   tokenu   NEWLINE(    (    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu	   BlankLineF   s    c             C   s   t  t j |  d | ƒS(   Nu   prefix(   u   Leafu   tokenu   NUMBER(   u   nu   prefix(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   NumberJ   s    c             C   s1   t  t j t t j d ƒ |  t t j d ƒ g ƒ S(   u   A numeric or string subscriptu   [u   ](   u   Nodeu   symsu   traileru   Leafu   tokenu   LBRACEu   RBRACE(   u
   index_node(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu	   SubscriptM   s    c             C   s   t  t j |  d | ƒS(   u   A string leafu   prefix(   u   Leafu   tokenu   STRING(   u   stringu   prefix(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   StringS   s    c       	      C   s"  |  j  d ƒ | j  d ƒ | j  d ƒ t t j d ƒ } | j  d ƒ t t j d ƒ } | j  d ƒ | | | | g } | oO | j  d ƒ t t j d ƒ } | j  d ƒ | j t t j | | g ƒ ƒ n t t j |  t t j	 | ƒ g ƒ } t t j
 t t j d ƒ | t t j d ƒ g ƒ S(   uu   A list comprehension of the form [xp for fp in it if test].

    If test is None, the "if test" part is omitted.
    u    u    u   foru   inu   ifu   [u   ](   u
   set_prefixu   Leafu   tokenu   NAMEu   appendu   Nodeu   symsu   comp_ifu	   listmakeru   comp_foru   atomu   LBRACEu   RBRACE(	   u   xpu   fpu   itu   testu   for_leafu   in_leafu
   inner_argsu   if_leafu   inner(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   ListCompW   s$    #$	c          	   C   s   x | D] } | j  ƒ  q Wt t j d ƒ t t j |  d d ƒt t j d d d ƒt t j | ƒ g } t t j | ƒ } | S(   uO    Return an import statement in the form:
        from package import name_leafsu   fromu   prefixu    u   import(   u   removeu   Leafu   tokenu   NAMEu   Nodeu   symsu   import_as_namesu   import_from(   u   package_nameu
   name_leafsu   leafu   childrenu   imp(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu
   FromImporto   s     c             C   sÇ   t  |  t ƒ o! |  j t ƒ  t ƒ  g k o d St  |  t ƒ o† t |  j ƒ d k op t  |  j d t ƒ oY t  |  j d t ƒ oB t  |  j d t ƒ o+ |  j d j d k o |  j d j d k S(   u(   Does the node represent a tuple literal?i   i    i   i   u   (u   )T(	   u
   isinstanceu   Nodeu   childrenu   LParenu   RParenu   Trueu   lenu   Leafu   value(   u   node(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   is_tuple‡   s    ,c             C   s   t  |  t ƒ oo t |  j ƒ d k oY t  |  j d t ƒ oB t  |  j d t ƒ o+ |  j d j d k o |  j d j d k S(   u'   Does the node represent a list literal?i   i    iÿÿÿÿu   [u   ](   u
   isinstanceu   Nodeu   lenu   childrenu   Leafu   value(   u   node(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   is_list“   s    c             C   s!   x |  D] } | o d Sq Wd S(   NTF(   u   Trueu   False(   u   lu   o(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   any¤   s
     	i    (   u   Setc             C   s   |  d  d  d … S(   Niÿÿÿÿ(    (   u   l(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   reversed²   s    u   sortedu   listu   setu   anyu   allu   tupleu   sumu   minu   maxc             c   s6   t  |  | ƒ } x  | o | Vt  | | ƒ } q Wd S(   ul  Follow an attribute chain.

    If you have a chain of objects where a.foo -> b, b.foo-> c, etc,
    use this to iterate over all objects in the chain. Iteration is
    terminated by getattr(x, attr) is None.

    Args:
        obj: the starting object
        attr: the name of the chaining attribute

    Yields:
        Each successive object in the chain.
    N(   u   getattr(   u   obju   attru   next(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu
   attr_chain½   s
     ue   for_stmt< 'for' any 'in' node=any ':' any* >
        | comp_for< 'for' any 'in' node=any any* >
     u¥   
power<
    ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
      'any' | 'all' | (any* trailer< '.' 'join' >) )
    trailer< '(' node=any ')' >
    any*
>
uN   
power<
    'sorted'
    trailer< '(' arglist<node=any any*> ')' >
    any*
>
c             C   s©   t  p7 t j t ƒ a t j t ƒ a t j t ƒ a d a  n t t t g } xU t | t |  d ƒ ƒ D]; \ } } i  } | j	 | | ƒ o | d |  k o d Sqf Wd S(   u   Returns true if node is in an environment where all that is required
        of it is being itterable (ie, it doesn't matter if it returns a list
        or an itterator).
        See test_map_nochange in test_fixers.py for some examples and tests.
        u   parentu   nodeTF(   u
   pats_builtu   patcompu   compile_patternu   p1u   p0u   p2u   Trueu   zipu
   attr_chainu   matchu   False(   u   nodeu   patternsu   patternu   parentu   results(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   in_special_contextã   s    
 $	c             C   sY   |  j  t j k o |  S|  j ƒ  }  |  j d  } |  _ t t j |  g ƒ } | | _ | S(   N(   u   typeu   symsu   suiteu   cloneu   parentu   Noneu   Node(   u   nodeu   parentu   suite(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu
   make_suiteú   s    	c             C   s@   x! | j  t j k o | j } q Wt | | |  ƒ } t | ƒ S(   uÞ    Returns true if name is imported from package at the
        top level of the tree which node belongs to.
        To cover the case of an import like 'import foo', use
        Null for the package and 'foo' for the name. (   u   typeu   symsu
   file_inputu   parentu   find_bindingu   bool(   u   packageu   nameu   nodeu   binding(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   does_tree_import  s
     c             C   s„  x}| j  D]r} d } | j t j k oP t |  | j  d ƒ o | St |  t | j  d ƒ | ƒ } | o
 | } qDnÌ| j t j t j	 f k o4 t |  t | j  d ƒ | ƒ } | o
 | } qDn|| j t j
 k o¹ t |  t | j  d ƒ | ƒ } | o
 | } qDx5t | j  d d … ƒ D]g \ } } | j t j k oH | j d k o8 t |  t | j  | d ƒ | ƒ } | o
 | } qq&q&Wn° | j t k o! | j  d j |  k o
 | } n t | |  | ƒ o
 | } nb | j t j k o t |  | | ƒ } n9 | j t j k o% t |  | j  d ƒ o
 | } qDn | o1 | p | S| j t j t j f k o | Sq
 q
 Wd S(	   uº    Returns the node which binds variable name, otherwise None.
        If optional argument package is supplied, only imports will
        be returned.
        See test cases for examples.i   iÿÿÿÿi   i   Nu   :i   i    (   u   childrenu   Noneu   typeu   symsu   for_stmtu   _findu   find_bindingu
   make_suiteu   if_stmtu
   while_stmtu   try_stmtu	   enumerateu   tokenu   COLONu   valueu	   _def_symsu   _is_import_bindingu   simple_stmtu	   expr_stmtu   import_nameu   import_from(   u   nameu   nodeu   packageu   childu   retu   nu   iu   kid(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   find_binding  sL    
   
 ## '

c             C   s„   | g } xt | ol | j  ƒ  } | j d k o$ | j t k o | j | j ƒ q | j t j k o | j |  k o | Sq Wd  S(   Ni   (	   u   popu   typeu   _block_symsu   extendu   childrenu   tokenu   NAMEu   valueu   None(   u   nameu   nodeu   nodes(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   _find=  s    	  #
c             C   sQ  |  j  t j k o| o|  j d } | j  t j k os xä | j D]a } | j  t j k o  | j d j | k o |  SqE | j  t j k o | j | k o |  SqE WqM| j  t j k o9 | j d } | j  t j k o | j | k o |  SqM| j  t j k o | j | k o |  Sn(|  j  t j	 k o| o% t
 |  j d ƒ j ƒ  | k o d S|  j d } | o t d | ƒ o d S| j  t j k o t | | ƒ o |  S| j  t j k o9 | j d } | j  t j k o | j | k o |  SqM| j  t j k o | j | k o |  S| o | j  t j k o |  Sn d S(   u›    Will reuturn node if node will import name, or node
        will import * from package.  None is returned otherwise.
        See test cases for examples. i   i   iÿÿÿÿi   u   asN(   u   typeu   symsu   import_nameu   childrenu   dotted_as_namesu   dotted_as_nameu   valueu   tokenu   NAMEu   import_fromu   stru   stripu   Noneu   _findu   import_as_namesu   import_as_nameu   STAR(   u   nodeu   nameu   packageu   impu   childu   lastu   n(    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   _is_import_bindingG  sB    
 	##	#	'##	#	NF(7   u   __doc__u   pgen2u   tokenu   pytreeu   Leafu   Nodeu   pygramu   python_symbolsu   symsu    u   patcompu
   KeywordArgu   LParenu   RParenu   Assignu   Noneu   Nameu   Attru   Commau   Dotu   ArgListu   Callu   Newlineu	   BlankLineu   Numberu	   Subscriptu   Stringu   ListCompu
   FromImportu   is_tupleu   is_listu   anyu	   NameErroru   setu   setsu   Setu   reversedu   consuming_callsu
   attr_chainu   p0u   p1u   p2u   Falseu
   pats_builtu   in_special_contextu
   make_suiteu   does_tree_importu   classdefu   funcdefu	   _def_symsu   find_bindingu   traileru   _block_symsu   _findu   _is_import_binding(    (    (    u/   /mit/python/lib/python3.0/lib2to3/fixer_util.pyu   <module>   sd   													


					*	
