
;d[c           @   s  d  d l  Z  d  d l m Z d  d l m Z m Z d  d l m Z 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 d e f d	     YZ d
 e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d   Z d e f d      YZ  d! e f d"     YZ! d#   Z" d$   Z# d%   Z$ d S(&   iN(   t
   OrderedSet(   t   astt   codeanalyze(   t	   ChangeSett   ChangeContents(   t   RefactoringError(   t   pycompat(   t   sourceutilst   similarfindert
   patchedastt   suitest   usefunctiont   _ExtractRefactoringc           B   s5   e  Z e d   Z d   Z d   Z e e d  Z RS(   c         C   sL   | |  _  | |  _ |  j | j   |  |  _ |  j | j   |  |  _ d  S(   N(   t   projectt   resourcet
   _fix_startt   readt   start_offsett   _fix_endt
   end_offset(   t   selfR   R   R   R   t   variable(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   __init__&   s    		c         C   s7   x0 | t  |  k  r2 | | j   r2 | d 7} q W| S(   Ni   (   t   lent   isspace(   R   t   sourcet   offset(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   -   s    %c         C   s5   x. | d k r0 | | d j    r0 | d 8} q W| S(   Ni    i   (   R   (   R   R   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   2   s    #c         C   s   t  |  j |  j |  j |  j | d |  j d k d | d | } t |  j   } t d |  j | f  } | j	 t
 |  j |   | S(   s
  Get the changes this refactoring makes

        :parameters:
            - `similar`: if `True`, similar expressions/statements are also
              replaced.
            - `global_`: if `True`, the extracted method/variable will
              be global.

        R   t   similart   make_globals   Extract %s <%s>(   t   _ExtractInfoR   R   R   R   t   kindt   _ExtractPerformert   extractR   t
   add_changeR   (   R   t   extracted_nameR   t   global_t   infot   new_contentst   changes(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   get_changes7   s    
(   t   __name__t
   __module__t   FalseR   R   R   R'   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   $   s   		t   ExtractMethodc           B   s   e  Z d    Z d Z RS(   c         O   s   t  t |   j | |   d  S(   N(   t   superR+   R   (   R   t   argst   kwds(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   N   s    t   method(   R(   R)   R   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR+   L   s   	t   ExtractVariablec           B   s   e  Z d    Z d Z RS(   c         O   s3   t  |  } t | d <t t |   j | |   d  S(   NR   (   t   dictt   TrueR,   R0   R   (   R   R-   R.   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   V   s    
R   (   R(   R)   R   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR0   T   s   	R   c           B   s   e  Z d  Z d   Z d   Z e d    Z d   Z d   Z e	 d  Z
 e d    Z e d    Z e d	    Z e d
    Z e d    Z e d    Z d Z e d    Z RS(   s3   Holds information about the extract to be performedc	   	      C   s   | |  _  | |  _ | j |  |  _ |  j j   |  _ |  j j |  _ |  j j |  _ | |  _	 | |  _
 | |  _ |  j | |  |  j   | |  _ d  S(   N(   R   R   t   get_pymodulet   pymodulet	   get_scopet   global_scopet   source_codeR   t   linest   new_nameR   R   t   _init_partst   _init_scopeR   (	   R   R   R   t   startt   endR9   R   R   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   a   s    					
c         C   s   |  j  |  |  j  | d t f |  _ |  j j |  j j |  j d   d } |  j j |  j j |  j d   d } | | f |  _ |  j j |  j d  |  j j	 |  j d  f |  _
 d  S(   NR=   i    i   (   t   _choose_closest_line_endR2   t   regiont   logical_linest   logical_line_inR8   t   get_line_numbert   region_linest   get_line_startt   get_line_endt   lines_region(   R   R<   R=   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR:   p   s    	 	 c         C   s
   |  j  j S(   N(   R4   R@   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR@   }   s    c         C   sq   |  j  d } |  j j |  } | j   d k rO | j   | k rO | j } n  | |  _ |  j |  j  |  _ d  S(   Ni    t   Module(	   RC   R6   t   get_inner_scope_for_linet   get_kindt	   get_startt   parentt   scopet   _get_scope_regiont   scope_region(   R   t
   start_lineRL   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR;      s    $	c         C   s2   |  j  j | j    |  j  j | j    d f S(   Ni   (   R8   RD   RJ   RE   t   get_end(   R   RL   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyRM      s    c         C   s   |  j  j |  } |  j  j |  } |  j  j |  } |  j | | !j   d k rg | r` | d S| Sn2 |  j | | !j   d k r t | t |  j   S| S(   Nt    i   (   R8   RB   RD   RE   R   t   stript   minR   (   R   R   R=   t   linenot
   line_startt   line_end(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR>      s    c         C   sB   |  j  |  j k oA |  j j |  j d  |  j j |  j d  k S(   Ni    i   (   R?   RF   R@   RA   RC   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   one_line   s    c         C   s   |  j  j d  k S(   N(   RL   RK   t   None(   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR#      s    c         C   s(   |  j  j d  k	 o' |  j  j j   d k S(   Nt   Class(   RL   RK   RX   RI   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR/      s    c         C   s   t  j |  j j |  j d  S(   Ni    (   R   t   get_indentsR4   R8   RC   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   indents   s    c         C   s,   |  j  r d St j |  j j |  j j    S(   Ni    (   R#   R   RZ   R4   R8   RL   RJ   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   scope_indents   s    	c         C   s   |  j  |  j d |  j d !S(   Ni    i   (   R   R?   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt	   extracted   s    c         C   s:   |  j  d k r3 t |  j  } t j |  |  _  n  |  j  S(   s1   Does the extracted piece contain return statementN(   t	   _returnedRX   t   _parse_textR]   R   t   _returns_last(   R   t   node(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   returned   s    N(   R(   R)   t   __doc__R   R:   t   propertyR@   R;   RM   R*   R>   RW   R#   R/   R[   R\   R]   RX   R^   Rb   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   ^   s   				t   _ExtractCollectorc           B   s   e  Z d  Z d   Z RS(   s6   Collects information needed for performing the extractc         C   sC   d  |  _ d  |  _ i  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   RX   t
   definitiont   body_patternt   checkst   replacement_patternt   matchest   replacementst   definition_location(   R   R$   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR      s    						(   R(   R)   Rc   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyRe      s   R   c           B   sP   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C   s   | |  _  t   |  j   d  S(   N(   R$   t   _ExceptionalConditionChecker(   R   R$   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR      s    	c         C   s   |  j    } t j |  j j  } | j } | j \ } } |  j j j |  } t	 j
 | |  } | j | | |  |  j | |  | j   S(   N(   t   _collect_infoR   t   ChangeCollectorR$   R   Rf   Rl   R8   RD   R   t   fix_indentationR!   t   _replace_occurrencest   get_changed(   R   t   extract_infot   contentRf   RT   R[   R   t   indented(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR       s    	c         C   s   x | j  D] } t j | j  } i  } xk | j   D]] } | j |  } | r t j | j |   \ } }	 |  j j	 | |	 !| | <q5 | | | <q5 W| j
   }
 | j |
 d |
 d | j |   q
 Wd  S(   Ni    i   (   Rj   R   t   CodeTemplateRi   t	   get_namest   get_astR	   t   node_regionR$   R   t
   get_regionR!   t
   substitute(   R   Rt   Rs   t   matcht   replacementt   mappingt   nameRa   R<   R=   R?   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyRq      s    c         C   s:   t  |  j  } |  j |  |  j |  |  j |  | S(   N(   Re   R$   t   _find_definitiont   _find_matchest   _find_definition_location(   R   t   extract_collector(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyRn      s
    c   
      C   s   |  j    } t j |  j j  } g  } x} | D]u \ } } | j | j | j | |  } d } xB | D]: }	 |	 j   \ } } | | k  re | j	 |	  | } qe qe Wq. W| | _
 d  S(   Ni(   t   _where_to_searchR   t   SimilarFinderR$   R4   t   get_matchesRg   Rh   Rz   t   appendRj   (
   R   t	   collectort   regionst   finderRj   R<   R=   t   region_matchest   last_match_endt   region_match(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR      s    c         C   sQ  |  j  j r@|  j  j s$ |  j  j r@ d t |  j  j j  f g S|  j  j r|  j  j r|  j  j	 j
 } g  } t |  j  j	  } x | j   D]s } | d k r t |  d k r q n  |  j  j j | j    } |  j  j j | j    } | j | | f  q W| S|  j  j r!|  j  j g S|  j  j |  j  j	 j
  g Sn |  j  j g Sd  S(   Ni    R/   (   R$   R   R   R#   R   R4   R7   R/   R   RL   RK   t   _get_function_kindt
   get_scopesR8   RD   RJ   RE   RP   R   RN   RM   R?   (   R   t   class_scopeR   t   method_kindRL   R<   R=   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   	  s(    	c         C   s   g  } xV | j  D]K } |  j j j | j   d  } |  j j j |  d } | j |  q Wt |  j |  } | j	   | j
   f | _ d  S(   Ni    (   Rj   R$   R8   RB   Rz   R@   RA   R   t   _DefinitionLocationFindert   find_linenot   find_indentsRl   (   R   R   t   matched_linesR|   R<   RO   t   location_finder(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   "  s    	c         C   sm   |  j  j r t |  j   } n t |  j   } | j   | _ | j   | _ | j   | _	 | j
   | _ d  S(   N(   R$   R   t   _ExtractVariablePartst   _ExtractMethodPartst   get_definitionRf   t   get_body_patternRg   t   get_replacement_patternRi   t
   get_checksRh   (   R   R   t   parts(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   ,  s    (
   R(   R)   R   R    Rq   Rn   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR      s   							
R   c           B   s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s9   | |  _  | |  _ | s5 |  j j |  j  j d  n  d  S(   Ni    (   R$   R   R   RC   (   R   R$   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   9  s    		c         C   s   |  j  j r# |  j  j r# |  j   S|  j  j s; |  j  j r |  j |  j  j  } |  j  j j   } t	 |  j
 | j   d g  } t j | |  S|  j   S(   Ni   (   R$   R   R   t   _get_before_lineR#   t   _find_toplevelRL   R4   Rx   t   sortedR   RP   R
   t   find_visiblet   _get_after_scope(   R   t   toplevelR   t   newlines(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   @  s    
 c         C   s>   | } | j  d  k	 r: x" | j  j  d  k	 r6 | j  } q Wn  | S(   N(   RK   RX   (   R   RL   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   J  s
    c         C   s[   |  j  j r5 |  j  j r5 t j |  j  j |  j    S|  j  j sM |  j  j rQ d S|  j  j S(   Ni    (	   R$   R   R   R   RZ   R8   R   R#   R\   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   Q  s    c         C   s(   |  j  j j j   } t j | |  j  S(   N(   R$   RL   t   pyobjectRx   R
   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   Z  s    c         C   s   |  j  j j   d S(   Ni   (   R$   RL   RP   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   ^  s    (   R(   R)   R   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   7  s   		
				Rm   c           B   s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s7   |  j  |  | j r& |  j |  n |  j |  d  S(   N(   t   base_conditionsRW   t   one_line_conditionst   multi_line_conditions(   R   R$   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   __call__d  s    	c         C   s   | j  d | j d k r) t d   n  | j d } | j j |  } | | j k rx | j   | k rx t d   n  yV | j | j  d | j  d !} | j	 r d | } n  t
 j |  r t d   n  Wn t k
 r t d   n Xd  S(   Ni   s&   Bad region selected for extract methodi    s   (%s)s:   A break/continue without having a matching for/while loop.s3   Extracted piece should contain complete statements.(   R?   RN   R   RC   R6   RH   RL   RP   R   RW   t   _UnmatchedBreakOrContinueFindert
   has_errorst   SyntaxError(   R   R$   t   end_linet	   end_scopeR]   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   k  s    !	c         C   sD   |  j  |  r t d   n  | j r@ | j r@ t d   n  d  S(   Ns#   Should extract complete statements.s0   Extract variable should not span multiple lines.(   t   _is_region_on_a_wordR   R   RW   (   R   R$   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   }  s    c         C   s   t  | j | j d | j d ! } t j |  } | d k rN t d   n  t j |  rl t d   n  | d k r t j |  r t d   n  | j | j k r t d   n  d  S(   Ni    i   s3   Extracted piece can have only one return statement.s-   Extracted piece cannot have yield statements.s$   Return should be the last statement.s3   Extracted piece should contain complete statements.(	   R_   R   R?   R   t   _return_countR   t   _yield_countR`   RF   (   R   R$   Ra   t   count(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    $c         C   sU   | j  d d k r0 |  j | | j  d d  sM |  j | | j  d d  rQ t Sd  S(   Ni    i   (   R?   t   _is_on_a_wordR2   (   R   R$   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   sj   | j  | } | j   p" | d k s? | d t | j   k rC t S| j  | d } | j   pi | d k S(   Nt   _i   (   R   t   isalnumR   R*   (   R   R$   R   t   prevt   next(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    (   R(   R)   R   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyRm   b  s   					R   c           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z 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   | |  _  |  j   |  _ d  S(   N(   R$   t   _create_info_collectort   info_collector(   R   R$   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    	c         C   s,   |  j  j r d |  j   Sd |  j   Sd  S(   Ns   
%s
s   
%s(   R$   R#   t   _get_function_definition(   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   sB   g  } | j  |  j    | j  |  j    t j |  j   |  S(   N(   t   extendt   _find_function_argumentst   _find_function_returnsR   t   make_patternt	   _get_call(   R   t	   variables(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   sU   g  } | j  |  j    | j  |  j    | j  |  j    t j |  j   |  S(   N(   R   R   R   t   _find_tempsR   R   t	   _get_body(   R   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s
    c         C   s5   t  j |  j j d  } |  j j r1 d | } n  | S(   Ni    s   (%s)(   R   Rp   R$   R]   RW   (   R   t   result(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s   t  j |  j j |  j    S(   N(   R   t
   find_tempsR$   R   R   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   sh   |  j  j rd |  j  j rd t |  j  j  d k rd t j |  j  j j j  } i d | |  j	   6Sn  i  S(   NR/   s   type=(
   R$   R/   R   R   RL   R   t   _pydefined_to_strRK   R   t   _get_self_name(   R   t
   class_name(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s   |  j  j j   d } |  j  j d | } |  j  j d | } t | | |  j  j  } |  j  j |  j  j d |  j  j d !} t |  } t	 j
 | |  | S(   Ni   i    (   R$   RL   RJ   RC   t   _FunctionInformationCollectorR#   R   RN   R_   R   t   walk(   R   t   zeroRO   R   R   t   bodyRa   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    	c         C   s   |  j    } |  j   } g  } |  j j r_ |  j j r_ t |  j j  d k r_ | j d  n  | j d |  j |   |  j	 |  } t
 j |  j j  } t
 j | |  } | j |  d j |  } | d S(   NR/   s   @staticmethod
s   def %s:
RQ   s   
(   R   R   R$   R/   R   R   RL   R   t   _get_function_signaturet   _get_unindented_function_bodyR   t
   get_indentR   t   indent_linest   join(   R   R-   t   returnsR   t   unindented_bodyR[   t   function_bodyRf   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s   t  |  } d } |  j   rt |  j   } | d  k rE t d   n  | | k ra | j |  n  | j d |  n  | |  j j d |  j	 |  S(   NRQ   s:   Extracting a method from a function with no self argument.i    s   (%s)(
   t   listt   _extracting_methodR   RX   R   t   removet   insertR$   R9   t   _get_comma_form(   R   R-   t   prefixt	   self_name(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s/   |  j  j o. |  j  j o. t |  j  j  d k S(   NR/   (   R$   R/   R   R   RL   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s'   |  j  j j j   } | r# | d Sd  S(   Ni    (   R$   RL   R   t   get_param_names(   R   t   param_names(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s   d } |  j  j r |  j  j r t |  j  j  d k rl |  j   } | | k r_ | j |  n  | d } q |  j  j j j j	   d } n  | d |  j  j
 |  j |  f S(   NRQ   R/   t   .s   %s(%s)(   R$   R/   R   R   RL   R   R   RK   R   t   get_nameR9   R   (   R   R-   R   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _get_function_call   s    c         C   sD   d } | r@ | | d 7} x# | d D] } | d | 7} q% Wn  | S(   NRQ   i    i   s   , (    (   R   t   namesR   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s   |  j  j r% |  j   } |  j |  S|  j   } |  j   } d } | r_ |  j |  d } n  |  j  j rt d } n  | |  j |  S(   NRQ   s    = s   return (   R$   RW   R   R   R   R   Rb   (   R   R-   R   t   call_prefix(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    	c         C   s  |  j  j r |  j  j r d S|  j  j sw |  j j |  j j @} | |  j j |  j j @|  j j |  j j	 @O} t
 |  S|  j  j d } | |  j  j d k r | t j d |  j  j  j   } n  |  j  j | |  j  j d !} t j |  } t
 |  j j j |   S(   Ni    s   \Si   (    (   R$   R#   R   RW   R   t
   prewrittenR   t   postreadt   maybe_writtent   writtenR   R?   RF   t   ret   searchR]   R<   R   t   _VariableReadsAndWritesFindert   find_reads_for_one_linerst   intersection(   R   R   R<   t   function_definitionR   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   "  s"    		
%	c         C   sF   |  j  j s |  j  j r g  S|  j j |  j j B} t | |  j j @ S(   N(   R$   RW   Rb   R   R   R   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   7  s
    	c         C   sb   |  j  j r  d t |  j  j  S|  j  j } t j | d  } | r^ | d |  j |  7} n  | S(   Ns   return i    s
   
return %s(   R$   RW   t   _join_linesR]   R   Rp   R   (   R   R   t   extracted_bodyR   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   >  s    (   R(   R)   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s$   																	R   c           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   | |  _  d  S(   N(   R$   (   R   R$   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   J  s    c         C   s(   |  j  j d t |  j  j  d } | S(   Ns    = s   
(   R$   R9   R   R]   (   R   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   M  s    $c         C   s   d |  j  j j   S(   Ns   (%s)(   R$   R]   RR   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   R  s    c         C   s
   |  j  j S(   N(   R$   R9   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   U  s    c         C   s   i  S(   N(    (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   X  s    (   R(   R)   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   H  s
   				R   c           B   sk   e  Z 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   sy   | |  _  | |  _ | |  _ t   |  _ t   |  _ t   |  _ t   |  _ t   |  _ t   |  _	 t
 |  _ t |  _ d  S(   N(   R<   R=   t	   is_globalR    R   R   R   R   R   t   postwrittenR2   t   host_functionR*   t   conditional(   R   R<   R=   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   ^  s    				c         C   s   |  j  | k o |  j k n rc | |  j k rc |  j sJ | |  j k r` |  j j |  q` qc n  |  j | k  r | |  j k r |  j j |  q n  d  S(   N(	   R<   R=   R   R   R   R   t   addR   R   (   R   R   RT   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _read_variablek  s    "c         C   s   |  j  | k o |  j k n rQ |  j r> |  j j |  qQ |  j j |  n  |  j  | k rs |  j j |  n  |  j | k  r |  j j |  n  d  S(   N(   R<   R=   R   R   R   R   R   R   (   R   R   RT   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _written_variablet  s    "	c         C   s   |  j  rp |  j rp t |  _ x* t | j  D] } |  j | | j  q, Wx | j D] } t j	 | |   qS Wnq |  j | j
 | j  t   } x! | j D] } t j	 | |  q Wx+ | j | j D] } |  j | | j  q Wd  S(   N(   R   R   R*   t   _get_argnamesR-   R   RT   R   R   R   R   R   R   R   R   (   R   Ra   R   t   childt   visitor(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _FunctionDef  s    		c         C   si   t  | j t j t j f  r7 |  j | j | j  n  t  | j t j  se |  j | j | j  n  d  S(   N(	   t
   isinstancet   ctxR   t   Storet   AugStoreR   t   idRT   R   (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _Name  s    c         C   s;   t  j | j |   x! | j D] } t  j | |   q Wd  S(   N(   R   R   t   valuet   targets(   R   Ra   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _Assign  s    c         C   s   |  j  | j | j  d  S(   N(   R   R   RT   (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt	   _ClassDef  s    c         C   sH   t  |  _ z. x' t j |  D] } t j | |   q WWd  t |  _ Xd  S(   N(   R2   R   R   t   get_child_nodesR   R*   (   R   Ra   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _handle_conditional_node  s
    	c         C   s   |  j  |  d  S(   N(   R  (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _If  s    c         C   s   |  j  |  d  S(   N(   R  (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _While  s    c         C   s   t  |  _ zr t j | j |   t j | j |   x! | j D] } t j | |   q< Wx! | j D] } t j | |   q` WWd  t |  _ Xd  S(   N(	   R2   R   R   R   t   itert   targetR   t   orelseR*   (   R   Ra   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _For  s    	(   R(   R)   R   R   R   R   R   R  R  R  R  R  R
  (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   \  s   											c         C   s   g  |  j  D]' } t | t j  r
 t j |  ^ q
 } |  j r\ | j t j |  j   n  |  j r | j t j |  j   n  | S(   N(   R-   R   R   t   ast_arg_typet   get_ast_arg_argt   varargR   t   kwarg(   t	   argumentsRa   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    '		R   c           B   sJ   e  Z d    Z d   Z d   Z d   Z e d    Z e d    Z RS(   c         C   s   t    |  _ t    |  _ d  S(   N(   t   setR   R   (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s`   t  | j t j t j f  r4 |  j j | j  n  t  | t j  s\ |  j j | j  n  d  S(   N(	   R   R   R   R   R   R   R   R   R   (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   sd   |  j  j | j  t   } x' t j |  D] } t j | |  q, W|  j j | j | j   d  S(   N(	   R   R   R   R   R   R  R   R   t   update(   R   Ra   R   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s
    	c         C   s   |  j  j | j  d  S(   N(   R   R   R   (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _Class  s    c         C   sx   |  j    d k r" t   t   f St |  t  rC |  j d  }  n  t |   } t   } t j | |  | j	 | j
 f S(   NRQ   s   utf-8(   RR   R  R   t   unicodet   encodeR_   R   R   R   R   R   (   t   codeRa   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   find_reads_and_writes  s    	c         C   sN   |  j    d k r" t   t   f St |   } t   } t j | |  | j S(   NRQ   (   RR   R  R_   R   R   R   R   (   R  Ra   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    	(	   R(   R)   R   R   R   R  t   staticmethodR  R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s   				R   c           B   sh   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e d	    Z RS(
   c         C   s   t  |  _ d |  _ d  S(   Ni    (   R*   t   errort
   loop_count(   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    	c         C   s   |  j  |  d  S(   N(   t   loop_encountered(   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR
    s    c         C   s   |  j  |  d  S(   N(   R  (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR    s    c         C   s   |  j  d 7_  x! | j D] } t j | |   q W|  j  d 8_  | j r t | j t t f  r x7 | j D] } t j | |   qm Wq t j | j |   n  d  S(   Ni   (   R  R   R   R   R	  R   R   t   tuple(   R   Ra   R   t   node_(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR    s    	c         C   s   |  j    d  S(   N(   t
   check_loop(   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   _Break  s    c         C   s   |  j    d  S(   N(   R  (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt	   _Continue	  s    c         C   s   |  j  d k  r t |  _ n  d  S(   Ni   (   R  R2   R  (   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR    s    c         C   s   d  S(   N(    (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    c         C   s   d  S(   N(    (   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR    s    c         C   sB   |  j    d k r t St |   } t   } t j | |  | j S(   NRQ   (   RR   R*   R_   R   R   R   R  (   R  Ra   R   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s    	(   R(   R)   R   R
  R  R  R  R  R  R   R  R  R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR     s   									c         C   s   |  j  j   S(   N(   R   RI   (   RL   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR      s    c         C   s%   t  j |  d  }  t j |   } | S(   Ni    (   R   Rp   R   t   parse(   R   Ra   (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR_   $  s    c         C   sf   g  } xP |  j    D]B } | j d  rB | j | d  j    q | j | j    q Wd j |  S(   Ns   \it    (   t
   splitlinest   endswithR   RR   R   (   R  R8   t   line(    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyR   *  s    (%   R   t   rope.base.utils.datastructuresR    t	   rope.baseR   R   t   rope.base.changeR   R   t   rope.base.exceptionsR   t   rope.base.utilsR   t   rope.refactorR   R   R	   R
   R   t   objectR   R+   R0   R   Re   R   R   Rm   R   R   R   R   R   R   R   R_   R   (    (    (    s4   lib/python2.7/site-packages/rope/refactor/extract.pyt   <module>   s.   ((
ff+@]	
+2		