B
    7r\                 @   s   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	m
Z
 dddd	d
ddddddddddddddhZdZd8ddZdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd9d*d+Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd:d4d5Zd6d7 ZdS );    N)cleandoc)tree)parser_cache)literal_evalforce_unicodefuncdefclassdefZimport_fromZimport_nameZtestZor_testZand_testZnot_testZ
comparisonexprZxor_exprZand_exprZ
shift_exprZ
arith_exprZ	atom_exprZtermZfactorZpowerZatom)	tryexceptfinallyelseifelifwithforwhileFc             C   s  g }| j }|dkrB|  }|dkr@| jj dkr@|dkr@||  n|dkrv||  x| jD ]}|t|dd7 }q\W n|dkr| jd	 d
kr| jd } | dkr|t| 7 }nTy
| j}W n tk
r   Y n6X | j tkr|s||  x|D ]}|t||7 }qW |S )z
    For static analysis.
    nameFparam=Z	expr_stmtT)
last_addedZ	decorator)()typeget_next_leafparentappendchildrenget_executable_nodesAttributeError_EXECUTE_NODES)noder   resulttypZ	next_leafchildr    r'   0lib/python3.7/site-packages/jedi/parser_utils.pyr       s0    




r    c             c   sB   | V  | j d }x,|jdkr$|V  n|jdks0P |j d }qW d S )Ncomp_forZcomp_if)r   r   )r*   Zlastr'   r'   r(   get_comp_fors9   s    


r+   c             C   s   | j d jdkS )z
    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
       r   )r   r   )for_stmtr'   r'   r(   for_stmt_defines_one_nameD   s    r.   c             C   sj   |j }| j |  k r| jks(n tdd }x8t| jD ]*\}}||j k rN|S | }|tkr8|}q8W dS )Nz!The node is not part of the flow.r   )	start_posend_pos
ValueError	enumerater   get_first_leaf_FLOW_KEYWORDS)Z	flow_noder#   r/   keywordir&   Z
first_leafr'   r'   r(   get_flow_branch_keywordN   s    
r7   c          	   C   sp   xj| j D ]`}|j|  kr$|jkrn q|jdkrHt|tjtjfsH|S y
t||S  t	k
rf   Y qX qW d S )N)Z	decoratedZsimple_stmtZsuiteZ
async_stmtZasync_funcdef)
r   r/   r0   r   
isinstancer   FlowZClassOrFuncget_statement_of_positionr!   )r#   poscr'   r'   r(   r:   ]   s    


r:   c             C   s*   |   }|dk	r&tt|j}t|S dS )z3 Returns a cleaned version of the docstring token. N )Zget_doc_noder   safe_literal_evalvaluer   )
scope_noder#   Zcleanedr'   r'   r(   clean_scope_docstringl   s
    rA   c             C   sJ   | d d   }|d dks$|dkr(dS yt| S  tk
rD   dS X d S )N   r   f)frZrfr=   )lowerr   SyntaxError)r?   Z	first_twor'   r'   r(   r>   {   s    r>   H   c             C   s   |dkr | j dkrd}n| jj}| j dkrPdddd |  D   d }n| jd	  }t	d
d|}| j
rd| j
  }nd}|| | }dt||S )z
    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
    Nlambdefz<lambda>r   r=   c             s   s   | ]}|  V  qd S )N)get_code).0r   r'   r'   r(   	<genexpr>   s    z%get_call_signature.<locals>.<genexpr>r   rB   z\s+ z ->
)r   r   r?   joinZ
get_paramsstripr   rI   resubZ
annotationtextwrapZwrap)r   widthcall_stringpZrtypecoder'   r'   r(   get_call_signature   s    

&rW   c             C   sx   d}| j dkr>x@|  D ] }|jjdkrt|| jjd}qW n| j dkrPt| }t| }|dkrd|S |sl|S d||f S )z<
    Return a document string including call signature.
    Nr   __init__)rT   )r   rH   z%s

%s)r   Ziter_funcdefsr   r?   rW   rA   )r@   Zcall_signaturer   docr'   r'   r(   get_doc_with_call_signature   s    

rZ   c             C   sJ   y
| j }W n" tk
r,   |  j|7  _Y nX x|D ]}t|| q4W dS )z$
    Move the `Node` start_pos.
    N)r   r!   linemove)r#   Zline_offsetr   r<   r'   r'   r(   r\      s    

r\   c             C   s   yj| j dkr| jd  j}nJ| j dkr:| jd  j}n.| j dkrZ| jd   j}n|   j}W n& tk
r~   dS  tk
r   dS X d|krdS ||dd }d	|kr|d|d	 }d
|kr|d|d
 }|S )zl
    returns (as string) any comment that appears on the same line,
    after the node, including the #
    r-      Z	with_stmt   r      N#rM   )	r   r   r3   prefixr   Zget_last_leafr!   r1   index)r#   Z
whitespacecommentr'   r'   r(   get_following_comment_same_line   s(    


re   c             C   s
   | j dkS )N)Z
file_inputr   r   rH   r*   )r   )r#   r'   r'   r(   is_scope   s    rf   c             C   s<   | j }x0|dk	r6|r$t|tjr$|S t|r.P |j }qW |S )z'
    Returns the underlying scope.
    N)r   r8   r   r9   rf   )r#   Zinclude_flowsZscoper'   r'   r(   get_parent_scope   s    

rg   c             C   s   t | j | jS )z
    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   Z_hashedlines)Zgrammarpathr'   r'   r(   get_cached_code_lines   s    rj   )F)rG   N)F)rP   rR   inspectr   Zparso.pythonr   Zparso.cacher   Zjedi._compatibilityr   r   r"   r4   r    r+   r.   r7   r:   rA   r>   rW   rZ   r\   re   rf   rg   rj   r'   r'   r'   r(   <module>   s0   


%


