
V]c           @   su  d  d l  Z  d  d l 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 d  d l m Z m Z d d	 d
 d d d d d d d d d d d d d d d d h Z d5 Z e d$  Z d%   Z d&   Z d'   Z d(   Z d)   Z d*   Z d+ d e e d,  Z d-   Z d.   Z d/   Z d0   Z e d1  Z e e  Z  d2   Z! d3   Z" d4   Z# d S(6   iN(   t   cleandoc(   t   WeakKeyDictionary(   t   tree(   t   parser_cache(   t   split_lines(   t   literal_evalt   force_unicodet   funcdeft   classdeft   import_fromt   import_namet   testt   or_testt   and_testt   not_testt
   comparisont   exprt   xor_exprt   and_exprt
   shift_exprt
   arith_exprt	   atom_exprt   termt   factort   powert   atomt   tryt   exceptt   finallyt   elset   ift   elift   witht   fort   whilec         C   sj  g  } |  j  } | d k rd |  j   } | t k rf|  j j  d k rf| d k rf| j |   qfn| d k r | j |   x |  j D] } | t | d t 7} q Wn | d k r |  j d d k rf|  j d	 }  |  d
 k r | t |   7} q qfnk y |  j } Wn t k
 rnK X|  j  t	 k rB| rB| j |   n  x! | D] } | t | |  7} qIW| S(   s   
    For static analysis.
    t   namet   paramt   =t	   expr_stmtt
   last_addedt	   decoratorit   )it   ((
   t   typet   get_next_leaft   Falset   parentt   appendt   childrent   get_executable_nodest   Truet   AttributeErrort   _EXECUTE_NODES(   t   nodeR'   t   resultt   typt	   next_leaft   childR0   (    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyR1      s0    	*c         c   sx   |  V|  j  d } x_ t rs | j d k r9 | j  d Vn* | j d k rP | Vn | j d k sc Pn  | j  d } q Wd  S(   Nit   comp_fori   t   sync_comp_fort   comp_if(   R0   R2   R+   (   R:   t   last(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   get_sync_comp_fors;   s    	c         C   s   |  j  d j d k S(   s   
    Returns True if only one name is returned: ``for x in y``.
    Returns False if the for loop is more complicated: ``for x, z in y``.

    :returns: bool
    i   R#   (   R0   R+   (   t   for_stmt(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   for_stmt_defines_one_nameH   s    c         C   s   | j  } |  j  | k  o& |  j k n s: t d   n  d  } xQ t |  j  D]@ \ } } | | j  k  ro | S| j   } | t k rP | } qP qP Wd S(   Ns!   The node is not part of the flow.i    (   t	   start_post   end_post
   ValueErrort   Nonet	   enumerateR0   t   get_first_leaft   _FLOW_KEYWORDS(   t	   flow_nodeR5   RA   t   keywordt   iR9   t
   first_leaf(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   get_flow_branch_keywordR   s    	"c         C   s   x |  j  D] } | j | k o- | j k n r
 | j d k ra t | t j t j f  ra | Sy t | |  SWq t	 k
 r q Xq
 q
 Wd  S(   Nt	   decoratedt   simple_stmtt   suitet
   async_stmtt   async_funcdef(   RM   RN   RO   RP   RQ   (   R0   RA   RB   R+   t
   isinstanceR   t   Flowt   ClassOrFunct   get_statement_of_positionR3   RD   (   R5   t   post   c(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyRU   a   s    "	c         C   s;   |  j    } | d k	 r7 t t | j   } t |  Sd S(   s3    Returns a cleaned version of the docstring token. t    N(   t   get_doc_nodeRD   R    t   safe_literal_evalt   valueR   (   t
   scope_nodeR5   t   cleaned(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   clean_scope_docstringp   s
    
c         C   sW   |  d  j    } | d d k s, | d k r0 d Sy t |   SWn t k
 rR d SXd  S(   Ni   i    t   ft   frt   rfRX   (   R`   Ra   (   t   lowerR   t   SyntaxError(   R[   t	   first_two(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyRZ      s    iH   c   	      C   s   | d k r3 |  j d k r$ d } q3 |  j j } n  |  j   } | rR | d } n  d d j d   | D  j   d } t j d d	 |  } |  j	 r | r d
 |  j	 j
   } n d } | | | } d j t j | |   S(   s   
    Generate call signature of this function.

    :param width: Fold lines if a line is longer than this value.
    :type width: int
    :arg func_name: Override function name when given.
    :type func_name: str

    :rtype: str
    t   lambdefs   <lambda>i   R*   RX   c         s   s   |  ] } | j    Vq d  S(   N(   t   get_code(   t   .0R$   (    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pys	   <genexpr>   s    R)   s   \s+t    s    ->s   
N(   RD   R+   R#   R[   t
   get_paramst   joint   stript   ret   subt
   annotationRf   t   textwrapt   wrap(	   R   t   widtht   call_stringt   omit_first_paramt   omit_return_annotationt   paramst   pt   rtypet   code(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   get_call_signature   s    	'c         C   sR   y |  j  } Wn  t k
 r/ |  j | 7_ n Xx | D] } t | |  q7 Wd S(   s$   
    Move the `Node` start_pos.
    N(   R0   R3   t   linet   move(   R5   t   line_offsetR0   RW   (    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyR{      s    c         C   s(  y |  j  d k r+ |  j d j   j } nk |  j  d k rS |  j d j   j } nC |  j  d k r |  j d j   j   j } n |  j   j   j } Wn# t k
 r d
 St k
 r d
 SXd | k r d
 S| | j	 d  } d | k r| | j	 d   } n  d	 | k r$| | j	 d	   } n  | S(   sl   
    returns (as string) any comment that appears on the same line,
    after the node, including the #
    R?   i   t	   with_stmti   R   i   t   #s   s   
N(
   R+   R0   RF   t   prefixR,   t   get_last_leafR3   RD   RC   t   index(   R5   t
   whitespacet   comment(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   get_following_comment_same_line   s(    c         C   s3   |  j  } | d k r) |  j d j  d k S| d k S(	   NR:   i   R;   t
   file_inputR   R   Re   (   R   R   R   Re   R;   (   R+   R0   (   R5   t   t(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   is_scope   s    	c            s"   t      t    f d  } | S(   Nc            sl   y   |  } Wn t  k
 r/ i  }   |  <n Xy | | SWn) t  k
 rg  | |  } | | <| SXd  S(   N(   t   KeyError(   t
   used_namesR5   t   include_flowst
   for_moduleR6   (   t   cachet   func(    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   wrapper   s    (   R   R-   (   R   R   (    (   R   R   s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   _get_parent_scope_cache   s    	c         C   s   |  j  } | d k r d Sx t r t |  sF | r t | t j  r | j d	 k r | j j	 d  } | j | j
 |  j
 k r |  j  j d k r |  j  j |  k r q |  j  j d k r |  j  j d |  k r q | j  } q q n  | S| j  } q W| S(
   s'   
    Returns the underlying scope.
    R   R   Re   t   :R$   t   tfpdefi    N(   R   R   Re   (   R.   RD   R2   R   RR   R   RS   R+   R0   R   RA   R#   (   R5   R   t   scopeR   (    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   get_parent_scope   s"    		$$(		c         C   s   t  |  j | j S(   s   
    Basically access the cached code lines in parso. This is not the nicest way
    to do this, but we avoid splitting all the lines again.
    (   R   t   _hashedt   lines(   t   grammart   path(    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   get_cached_code_lines  s    c         C   st   t  |  j d t | d |  j d  } | d } |  j | d k rU | |  j 8} n  | d |  | d <d j |  S(   s3   
    Cuts of the value of the leaf at position
    t   keependsi    i   iRX   (   R   R[   R2   Rz   t   columnRj   (   t   leaft   positionR   R   (    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   cut_value_at_position  s    (
c         C   s   t  j d |  j  j d  S(   Ns   \w*("""|'{3}|"|')i   (   Rl   t   matchR[   t   group(   R   (    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   get_string_quote(  s    (	   R   R   R   R   R   R   R    R!   R"   ($   Rl   Ro   t   inspectR    t   weakrefR   t   parso.pythonR   t   parso.cacheR   t   parsoR   t   jedi._compatibilityR   R   R4   RG   R-   R1   R>   R@   RL   RU   R^   RZ   RD   Ry   R{   R   R   R   R   t   get_cached_parent_scopeR   R   R   (    (    (    s0   lib/python2.7/site-packages/jedi/parser_utils.pyt   <module>   s<   %		
				 							