
ŕZc           @   s   d  d l  Z  d  d l Z d  d l Z d  d l m Z m Z m Z d  d l m Z y e	 Wn e
 k
 rw e e f Z	 n Xe d  Z e d  Z d   Z d   Z d e j f d	     YZ d
 e f d     YZ d e f d     YZ d S(   iN(   t   astt   codeanalyzet
   exceptions(   t   pycompatc         C   s   t  t j |   |  |  S(   s   Adds ``region`` and ``sorted_children`` fields to nodes

    Adds ``sorted_children`` field only if `sorted_children` is True.

    (   t	   patch_astR    t   parse(   t   sourcet   sorted_children(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   get_patched_ast   s    c         C   s9   t  |  d  r |  St | d | } t j |  |  |  S(   s  Patches the given node

    After calling, each node in `node` will have a new field named
    `region` that is a tuple containing the start and end offsets
    of the code that generated it.

    If `sorted_children` is true, a `sorted_children` field will
    be created for each node, too.  It is a list containing child
    nodes as well as whitespaces and comments that occur between
    them.

    t   regiont   children(   t   hasattrt   _PatchingASTWalkerR    t   call_for_nodes(   t   nodeR   R   t   walker(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR      s
    c         C   s   |  j  S(   s$   Get the region of a patched ast node(   R	   (   t   patched_ast_node(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   node_region+   s    c         C   s\   g  } xF |  j  D]; } t | t j  r> | j t |   q | j |  q Wd j |  S(   s   Extract source form a patched AST node with `sorted_children` field

    If the node is patched with sorted_children turned off you can use
    `node_region` function for obtaining code using module source code.
    t    (   R   t
   isinstanceR    t   ASTt   appendt	   write_astt   join(   R   t   resultt   child(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR   0   s    t   MismatchedTokenErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR   ?   s   R   c           B   s  e  Z e d   Z e   Z e   Z e   Z d   Z e e d  Z	 d   Z
 d   Z d   Z d   Z i d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d d' 6d d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d8 6d9 d: 6d; d< 6Z d=   Z d>   Z d?   Z d@   Z dA   Z dB   Z dC   Z dD   Z dE   Z dF   Z dG   Z dH   Z dI   Z dJ   Z dK   Z dL   Z dM   Z dN   Z  dO   Z! dP   Z" dQ   Z# dR   Z$ dS   Z% dT   Z& dU   Z' dV   Z( dW   Z) dX   Z* dY   Z+ dZ   Z, d[   Z- d\   Z. d]   Z/ d^   Z0 d_   Z1 d`   Z2 da   Z3 db   Z4 dc   Z5 dd   Z6 de   Z7 df   Z8 dg   Z9 dh   Z: di   Z; dj   Z< dk   Z= dl   Z> dm   Z? dn   Z@ do   ZA dp   ZB dq   ZC dr   ZD ds   ZE dt   ZF du   ZG dv   ZH dw   ZI dx   ZJ dy   ZK dz   ZL d{   ZM d|   ZN d}   ZO d~   ZP RS(   c         C   s7   t  |  |  _ | |  _ t j |  |  _ g  |  _ d  S(   N(   t   _SourceR   R
   R   t   SourceLinesAdaptert   linest   children_stack(   t   selfR   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   __init__E   s    	c         C   s   t  |  d | j j d   } | d  k	 r2 | |  St j d | j j t  |  j j |  j j f | _	 |  j
 r t j |  | _ n  d  S(   Nt   _s&   Unknown node type <%s>; please report!(   t   getattrt	   __class__R   t   Nonet   warningst   warnt   RuntimeWarningR   t   offsetR	   R
   R    t   get_childrenR   (   R!   R   t   method(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   __call__O   s    
		c         C   s  t  | d  r- t j d | j j t  d  St j |  } |  j j	 |  t j   } g  } |  j
 j } | } t }	 x| r| j   }
 |
 d  k r qy n  |  j
 j } t |
 t j  r t j |
 |   |
 j d } n |
 |  j k r|  j
 j d |  j    } nr |
 |  j k r)|  j
 j   } nQ |
 d k rG|  j
 j   } n3 |
 |  j k rh|  j
 j   } n |  j
 j |
  } |  j
 | d | d !}
 | d } |	 s| j	 |  j
 | | ! |  j r| j	 |  j
 | | ! qn t }	 | } |  j ry | j	 |
  qy qy W|  j | | |  } | r;|  j  | | |  } n  | r|  j rd| j! |  j
 d | ! n  |  j
 |  j
 j } |  j
 j |  |  j r| j	 |  n  d } n  |  j r| | _" n  | |  j
 j f | _ |  j j#   d  S(   NR	   s2   Node <%s> has been already patched; please report!i    t   ends   !=i   ($   R   R'   R(   R%   R   R)   t   collectionst   dequeR    R   R   R*   t   Truet   popleftR&   R   R    R   R   R	   t   Stringt   consume_stringt   _find_next_statement_startt   Numbert   consume_numbert   consume_not_equalt   semicolon_or_as_in_exceptt   consume_except_as_or_semicolont   consumeR
   t   Falset   _handle_parenst   _eat_surrounding_parenst
   appendleftR   t   pop(   R!   R   t   base_childrent
   eat_parenst
   eat_spacesR
   t   formatst   suspected_startt   startt   first_tokenR   R*   t   token_startR	   t
   end_spaces(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _handleZ   sp    	
						c   
      C   s   |  j  |  \ } } |  j j } d } x* t |  D] } |  j j d  d } q4 W| d k	 r |  j r | j |  j | | ! q n  | }	 x, t |  D] } |  j j d d |	  }	 q W|	 | k r |  j r | j	 |  j |	 | ! n  |	 } n  | S(   s(   Changes `children` and returns new startt   )i   t   (i    N(
   t   _count_needed_parensR   R*   R&   t   rangeR;   R
   R   t   rfind_tokenR?   (
   R!   R
   RF   RD   t   openst   closest   old_endt   new_endt   it	   new_start(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR=      s     			c   	      C   s   |  j  j d | |  } | d  k	 r | } |  j  j } | } |  j rp | j |  j  | d | ! | j d  n  |  j  j d  \ } } |  j r | j |  j  | | ! | j d  q n  | S(   NRL   i   RK   (   R   RO   R&   R*   R
   R?   R;   R   (	   R!   R
   RE   RF   t   indext	   old_startt
   old_offsetRH   t	   token_end(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR>      s    		c         C   s  d } d } x | D] } t  | t  s. q n  | d k s | d d k rP q n  d } x | t |  k  r	| | d k r | d k r | d 8} q | d 7} n  | | d k r | d 7} n  | | d k r y | j d |  } Wq t k
 r Pq Xn  | d 7} qY Wq W| | f S(	   Ni    R   s   '"RK   i   RL   t   #s   
(   R   t
   basestringt   lenRV   t
   ValueError(   R!   R
   RF   RP   R   RV   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyRM      s,    c         C   sg   xT t  |  j  D]C } x: | D]2 } t | t j  r | j |  j j | j  Sq Wq Wt	 |  j
 j
  S(   N(   t   reversedR    R   R    t   stmtt
   col_offsetR   t   get_line_startt   linenoR\   R   (   R!   R
   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR5      s    t   andt   Andt   ort   Ort   +t   Addt   -t   Subt   *t   Multt   /t   Divt   %t   Mods   **t   Pows   <<t   LShifts   >>t   RShiftt   |t   BitOrt   &t   BitAndt   ^t   BitXors   //t   FloorDivt   ~t   Invertt   nott   Nott   UAddt   USubs   ==t   Eqs   !=t   NotEqt   <t   Lts   <=t   LtEt   >t   Gts   >=t   GtEt   ist   Iss   is nott   IsNott   int   Ins   not int   NotInc         C   s   |  j  | j j j d  S(   Nt    (   t
   _operatorsR%   R   t   split(   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _get_op   s    c         C   s#   |  j  | | j d | j g  d  S(   Nt   .(   RJ   t   valuet   attr(   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt
   _Attribute   s    c         C   sL   d | j  g } | j r8 | j d  | j | j  n  |  j | |  d  S(   Nt   assertt   ,(   t   testt   msgR   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Assert   s
    	c         C   sF   |  j  | j d  } | j d  | j | j  |  j | |  d  S(   Nt   =(   t   _child_nodest   targetsR   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Assign   s    c         C   sO   | j  g } | j |  j | j   | j d | j g  |  j | |  d  S(   NR   (   t   targett   extendR   t   opR   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt
   _AugAssign   s    c         C   s    |  j  | d | j d g  d  S(   Nt   `(   RJ   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Repr   s    c         C   s:   | j  g |  j | j  | j g } |  j | |  d  S(   N(   t   leftR   R   t   rightRJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _BinOp  s    &c         C   s3   |  j  | |  j | j |  j | j  d   d  S(   Ni    (   RJ   R   t   valuesR   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _BoolOp  s    c         C   s   |  j  | d g  d  S(   Nt   break(   RJ   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Break  s    c         C   s  d   } | j  d g } g  } t | j  } x[ t | j  D]J \ } } t t d  rz t | t j  rz | j	 |  q= | j	 |  q= Wt
 | d d   r | j	 | j  n  | j d |  | j |  j | d   | r|t |  d k r| j	 d  n  xx t |  D]g \ } } | t
 | d d   k rB| j	 d  n  | j	 |  | d	 t |  k  r| j	 d  qqWn  t
 | d
 d   rt |  d k r| j	 d  n  | j d | j g  n  | j	 d  |  j | |  d  S(   Nc         S   s8   t  |  t j  r( |  j j |  j j f S|  j |  j f S(   N(   R   R    t   keywordR   Rb   R`   (   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _arg_sort_key  s    RL   t   Starredt   starargst   keyR   i   Rk   i   t   kwargss   **RK   (   t   funct   listt   keywordst	   enumeratet   argsR   R    R   R   R   R$   R&   R   t   sortR   R   R\   R   RJ   (   R!   R   R   R
   t   unstarred_argst   starred_and_keywordsRT   t   arg(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Call  s6    	!c         C   s   g  } t  | d d   rI x. | j D]  } | j d  | j |  q" Wn  | j d | j g  | j r | j d  | j |  j | j d   | j d  n  | j d  | j | j  |  j	 | |  d  S(   Nt   decorator_listt   @t   classRL   R   RK   t   :(
   R$   R&   R   R   R   t   namet   basesR   t   bodyRJ   (   R!   R   R
   t	   decorator(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt	   _ClassDef4  s    	c         C   ss   g  } | j  | j  xF t | j | j  D]/ \ } } | j |  j |   | j  |  q, W|  j | |  d  S(   N(   R   R   t   zipt   opst   comparatorsR   R   RJ   (   R!   R   R
   R   t   expr(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _CompareC  s    "c         C   s*   |  j  | d g |  j | j d   d  S(   Nt   delR   (   RJ   R   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _DeleteK  s    c         C   s   |  j  | |  j g  d  S(   N(   RJ   R6   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _NumN  s    c         C   s   |  j  | |  j g  d  S(   N(   RJ   R3   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _StrQ  s    c         C   s   |  j  | d g  d  S(   Nt   continue(   RJ   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt	   _ContinueT  s    c         C   s   g  } | j  d  | j r xq t t | j | j   D]Q \ } \ } } | j | d | g  | t | j  d k  r8 | j  d  q8 q8 Wn  | j  d  |  j | |  d  S(   Nt   {R   i   R   t   }(   R   t   keysR   R   R   R   R\   RJ   (   R!   R   R
   RV   R   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _DictW  s    	.c         C   s   |  j  | d g  d  S(   Ns   ...(   RJ   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt	   _Ellipsisb  s    c         C   s   |  j  | | j g  d  S(   N(   RJ   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Expre  s    c         C   st   g  } | j  d | j g  | j r> | j  d | j g  n  | j r` | j  d | j g  n  |  j | |  d  S(   Nt   execR   R   (   R   R   t   globalst   localsRJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Exech  s    		c         C   sc   g  } xF t  | j  D]5 \ } } | d k r> | j d  n  | j |  q W|  j | |  d  S(   Ni    R   (   R   t   dimsR   RJ   (   R!   R   R
   RV   t   dim(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt	   _ExtSliceq  s    c         C   sn   d | j  d | j d g } | j | j  | j rZ | j d d g  | j | j  n  |  j | |  d  S(   Nt   forR   R   t   else(   R   t   iterR   R   t   orelseRJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Fory  s    	c         C   su   d g } | j  r) | j d | j   n  | j | j p; d d g  | j |  j | j d   |  j | |  d  S(   Nt   fromR   R   t   importR   (   t   levelR   R   t   moduleR   t   namesRJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _ImportFrom  s    		
c         C   sB   | j  g } | j r. | j d | j g  n  |  j | |  d  S(   Nt   as(   R   t   asnameR   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _alias  s    	c         C   s   g  } y t  | d  } Wn# t k
 r> t  | d d   } n X| rs x+ | D]  } | j d  | j |  qL Wn  | j d | j d | j g  | j d d g  | j | j  |  j | |  d  S(   NR   t
   decoratorsR   t   defRL   RK   R   (	   R$   t   AttributeErrorR&   R   R   R   R   R   RJ   (   R!   R   R
   R   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _FunctionDef  s    c         C   sN  g  } t  | j  } d  g t |  t | j  t  | j  } xX t t | |   D]A \ } \ } } | d k r | j d  n  |  j | | |  qX W| j	 d  k	 r | r | j d  n  | j
 d t j | j	  g  n  | j d  k	 r:| s| j	 d  k	 r| j d  n  | j
 d t j | j  g  n  |  j | |  d  S(   Ni    R   Rk   s   **(   R   R   R&   R\   t   defaultsR   R   R   t   _add_args_to_childrent   varargR   R   t   get_ast_arg_argt   kwargRJ   (   R!   R   R
   R   R   RV   R   t   default(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt
   _arguments  s"    (""c         C   sb   t  | t t f  r( |  j | |  n | j |  | d  k	 r^ | j d  | j |  n  d  S(   NR   (   R   R   t   tuplet   _add_tuple_parameterR   R&   (   R!   R
   R   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR     s    c         C   s   | j  d  xk t |  D]] \ } } | d k rB | j  d  n  t | t t f  rj |  j | |  q | j  |  q W| j  d  d  S(   NRL   i    R   RK   (   R   R   R   R   R   R   (   R!   R
   R   RV   t   token(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR     s    c         C   s6   | j  g } | j | j  |  j | | d t d  S(   NRB   (   t   eltR   t
   generatorsRJ   R1   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _GeneratorExp  s    c         C   sf   d | j  d | j g } | j rR x. | j D]  } | j d  | j |  q+ Wn  |  j | |  d  S(   NR   R   t   if(   R   R   t   ifsR   RJ   (   R!   R   R
   t   if_(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _comprehension  s    	c         C   s9   |  j  | j d  } | j d d  |  j | |  d  S(   NR   i    t   global(   R   R   t   insertRJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Global  s    c         C   s   |  j  |  r d g } n	 d g } | j | j d g  | j | j  | j r t | j  d k r |  j  | j d  r n | j d d g  | j | j  n  |  j | |  d  S(   Nt   elifR   R   i   i    R   (   t   _is_elifR   R   R   R   R\   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _If  s    		+c         C   sn   t  | t j  s t S|  j j | j  | j } |  j | | d !} |  j | d | d !} d | | f k S(   Ni   i   i   R  (	   R   R    t   IfR<   R   Ra   Rb   R`   R   (   R!   R   R*   t   wordt   alt_word(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR    s    c         C   s(   |  j  | | j d | j d | j g  S(   NR   R   (   RJ   R   R   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _IfExp  s    c         C   s9   d g } | j  |  j | j d   |  j | |  d  S(   NR   R   (   R   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Import  s    	c         C   sX   g  } | j  d  k r( | j | j  n | j | j  d | j g  |  j | |  d  S(   NR   (   R   R&   R   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _keyword  s
    c         C   s&   |  j  | d | j d | j g  d  S(   Nt   lambdaR   (   RJ   R   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Lambda  s    c         C   s1   |  j  | d g |  j | j d  d g  d  S(   Nt   [R   t   ](   RJ   R   t   elts(   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _List  s    c         C   s@   d | j  g } | j | j  | j d  |  j | |  d  S(   NR  R  (   R   R   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt	   _ListComp  s    c         C   sd   | j  r: |  j | d g |  j | j  d  d g  d  St j d t  |  j | d d g  d  S(   NR   R   R   s3   Tried to handle empty <Set> literal; please report!s   set(RK   (   R  RJ   R   R'   R(   R)   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Set  s    		$	c         C   s@   d | j  g } | j | j  | j d  |  j | |  d  S(   NR   R   (   R   R   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _SetComp  s    c         C   sV   d g } | j  | j d | j g  | j  | j  | j d  |  j | |  d  S(   NR   R   R   (   R   R   R   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt	   _DictComp  s
    	c         C   s#   |  j  | t | j  d t d  S(   NRC   (   RJ   R   R   R1   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Module%  s    c         C   s   |  j  | | j g  d  S(   N(   RJ   t   id(   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Name(  s    c         C   s    |  j  | t | j  g  d  S(   N(   RJ   t   strR   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _NameConstant+  s    c         C   s   |  j  | | j g  d  S(   N(   RJ   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _arg.  s    c         C   s   |  j  | d g  d  S(   Nt   pass(   RJ   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Pass1  s    c         C   s   d g } | j  rD | j d | j  g  | j rD | j d  qD n  | j |  j | j d   | j sy | j d  n  |  j | |  d  S(   Nt   prints   >>R   (   t   destR   R   R   R   t   nlRJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Print4  s    				c         C   sJ   d   } d   } t  j r* | |  } n | |  } |  j | |  d  S(   Nc         S   sE   d g } |  j  r% | j |  j   n  |  j rA | j |  j  n  | S(   Nt   raise(   t   excR   t   cause(   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   get_python3_raise_childrenA  s    			c         S   s{   d g } |  j  r% | j |  j   n  |  j rN | j d  | j |  j  n  |  j rw | j d  | j |  j  n  | S(   NR#  R   (   t   typeR   t   instt   tback(   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   get_python2_raise_childrenI  s    				(   R   t   PY2RJ   (   R!   R   R&  R*  R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Raise?  s    			c         C   s9   d g } | j  r% | j | j   n  |  j | |  d  S(   Nt   return(   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _ReturnZ  s    		c         C   sl   g  } xO t  | j  D]> \ } } | d k r> | j d  n  | r | j |  q q W|  j | |  d  S(   Ni    R   (   R   t   nodesR   RJ   (   R!   R   R
   RV   t   slice(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt	   _Sliceobj`  s    c         C   s   |  j  | | j g  d  S(   N(   RJ   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Indexi  s    c         C   s&   |  j  | | j d | j d g  d  S(   NR  R  (   RJ   R   R0  (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt
   _Subscriptl  s    c         C   s   g  } | j  r" | j | j   n  | j d  | j rK | j | j  n  | j rt | j d  | j | j  n  |  j | |  d  S(   NR   (   t   lowerR   t   uppert   stepRJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Sliceo  s    			c         C   s.  t  } t } t | j  d k r t j r\ t | j d t j	  } t
 t | j   } q t j r y# t | j d t j  } t } Wq t k
 r q Xq n  g  } | s | r | j d d g  n  | j | j  t j r | j | j  n  | j d d g  | j | j  |  j | |  d  S(   Ni   i    t   tryR   t   finally(   R<   R1   R\   t	   finalbodyR   R+  R   R   R    t	   TryExceptt   boolt   PY3t   handlerst   ExceptHandlert
   IndexErrorR   RJ   (   R!   R   t   is_there_except_handlert   not_empty_bodyR
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _TryFinally{  s*    		

	c         C   so   d d g } | j  | j  | j  | j  | j r[ | j  d d g  | j  | j  n  |  j | |  d  S(   NR8  R   R   (   R   R   R>  R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt
   _TryExcept  s    	c         C   s0   t  | j  r |  j |  n |  j |  d  S(   N(   R\   R:  RC  RD  (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Try  s    c         C   s   |  j  |  d  S(   N(   t   _excepthandler(   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _ExceptHandler  s    c         C   s   d g } | j  r% | j | j   n  | j rQ | j |  j  | j | j  n  | j d  | j | j  |  j | |  d  S(   Nt   exceptR   (   R'  R   R   R9   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyRF    s    			c         C   sK   | j  r1 |  j | |  j | j  d  d t n |  j | d d g  d  S(   NR   RB   RL   RK   (   R  RJ   R   R1   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Tuple  s    	
c         C   s6   |  j  | j  } | j | j  |  j | |  d  S(   N(   R   R   R   t   operandRJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _UnaryOp  s    c         C   s9   d g } | j  r% | j | j   n  |  j | |  d  S(   Nt   yield(   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Yield  s    		c         C   se   d | j  d g } | j | j  | j rQ | j d d g  | j | j  n  |  j | |  d  S(   Nt   whileR   R   (   R   R   R   R   RJ   (   R!   R   R
   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _While  s    	c         C   s   g  } xO t  j |  D]> } | j d | j g  | j r | j d | j g  q q W| j d  | j | j  |  j | |  d  S(   Nt   withR   R   (   R   t   get_ast_with_itemsR   t   context_exprt   optional_varsR   R   RJ   (   R!   R   R
   t   item(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _With  s    	c         C   sZ   g  } xM t  |  D]? \ } } | j |  | t |  d k  r | j |  q q W| S(   Ni   (   R   R   R\   (   R!   R/  t	   separatorR
   RV   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR     s    c         C   s   |  j  | | j g  d  S(   N(   RJ   R   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   _Starred  s    (Q   R   R   R<   R"   t   objectR6   R3   R9   R-   RJ   R=   R>   RM   R5   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R  R
  R  R  R  R  R  R  R  R  R  R  R  R  R  R"  R,  R.  R1  R2  R3  R7  RC  RD  RE  RG  RF  RI  RK  RM  RO  RU  R   RW  (    (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR   C   s   				A				
										&														
																			
																										
	R   c           B   s   e  Z d    Z d   Z d d  Z d   Z d   Z d   Z d d  Z	 d   Z
 d   Z d d	  Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d Z d Z d Z RS(   c         C   s   | |  _  d |  _ d  S(   Ni    (   R   R*   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR"     s    	c         C   s   yI xB t  rG |  j j | |  j  } |  j | |  r: Pq |  j   q WWn3 t t f k
 r~ t d | |  j	   f   n X| t
 |  |  _ | |  j f S(   Ns"   Token <%s> at %s cannot be matched(   R1   R   RV   R*   t   _good_tokent   _skip_commentR]   t	   TypeErrorR   t   _get_locationR\   (   R!   R   t
   new_offset(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR;     s    	c         C   sY   t  j d  k r@ t j   } d | | f } t j |  t  _ n  t  j } |  j | |  S(   Ns   (%s)((\s|\\\n|#[^\n]*\n)*(%s))*(   R   t   _string_patternR&   R   t   get_string_patternt   ret   compilet   _consume_pattern(   R!   R.   t   originalt   patternt	   repattern(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR4     s    	c         C   s@   t  j d  k r* t j |  j    t  _ n  t  j } |  j |  S(   N(   R   t   _number_patternR&   R`  Ra  t   _get_number_patternRb  (   R!   Re  (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR7     s
    	c         C   s:   t  j d  k r$ t j d  t  _ n  t  j } |  j |  S(   Ns   <>|!=(   R   t   _not_equals_patternR&   R`  Ra  Rb  (   R!   Re  (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR8     s    	c         C   s   t  j d  } |  j |  S(   Ns   as|,(   R`  Ra  Rb  (   R!   Re  (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR:     s    c         C   s   | d k r |  j } n  y |  j j d | |  } Wn t k
 rH t SXy |  j j d | |  } Wn t k
 ry t SX| | k  S(   s,   Checks whether consumed token is in commentsRZ   s   
N(   R&   R*   R   t   rindexR]   R1   R<   (   R!   R   R*   RF   t   comment_indext   new_line_index(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyRY    s    c         C   s#   |  j  j d |  j d  |  _ d  S(   Ns   
i   (   R   RV   R*   (   R!   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyRZ    s    c         C   s3   |  j  |  j  j d  } t |  t | d  f S(   Ns   
i(   R   R*   R   R\   (   R!   R   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR\  !  s    c         C   s   xo t  rq | d  k r' t |  j  } n  | j |  j |  j |  } |  j | j   | j    rd Pq |  j	   q W| j
   |  _ | j   | j
   f S(   N(   R1   R&   R\   R   t   searchR*   RY  t   groupRF   RZ  R.   (   R!   Re  R.   t   match(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyRb  %  s    	c         C   s&   |  j  j | |  j  } |  |  j | !S(   N(   R   RV   R*   (   R!   R   R]  (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt
   till_token1  s    c         C   sj   | } x] t  re y> |  j j | | |  } |  j | | d | rF | S| } Wq	 t k
 ra d  SXq	 Wd  S(   NRF   (   R1   R   Ri  RY  R]   R&   (   R!   R   RF   R.   RV   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyRO   5  s    	
c         C   s   |  | |  j  !S(   N(   R*   (   R!   R*   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   from_offsetA  s    c         C   s   |  j  j | d |  S(   Ni    (   R   Ri  (   R!   Rd  R*   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   find_backwardsD  s    c         C   s   |  j  | S(   N(   R   (   R!   RV   (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   __getitem__G  s    c         C   s   |  j  | | !S(   N(   R   (   R!   RT   t   j(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   __getslice__J  s    c         C   s   d } d | S(   Ns   \-?(0x[\da-fA-F]+|\d+)[lL]?s(   (%s(\.\d*)?|(\.\d+))([eE][-+]?\d+)?[jJ]?(    (   R!   t   integer(    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyRg  M  s    N(   R   R   R"   R;   R&   R4   R7   R8   R:   RY  RZ  R\  Rb  Ro  RO   Rp  Rq  Rr  Rt  Rg  R^  Rf  Rh  (    (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyR     s(   															(   R/   R`  R'   t	   rope.baseR    R   R   t   rope.base.utilsR   R[   t	   NameErrorR  t   bytesR<   R   R   R   R   t	   RopeErrorR   RX  R   R   (    (    (    s7   lib/python2.7/site-packages/rope/refactor/patchedast.pyt   <module>   s"   			  