o
    Zh*                     @   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	 d dl
mZ d dlmZ h dZd	Zd4ddZdd Zdd Zdd Zdd Zdd Zdd Z		
d5ddZdd Zdd Zd d! Zd"d# Zd4d$d%ZeeZd&d' Zd(d) Zd*d+ Z d,d- Z!d.d/ Z"e"d0d1 Z#e"d2d1 Z$e"d3d1 Z%dS )6    N)literal_eval)cleandocWeakKeyDictionary)tree)parser_cache)split_lines>   Zand_testfuncdefatomterm	atom_exprZ
comparisonZxor_exprtestZimport_fromZnot_testZ
arith_exprfactorZor_testimport_nameexprZand_exprpowerZ
shift_exprclassdef)	tryexceptfinallyelseifelifwithforwhileFc                 C   s  g }| j }|dkr"|  }|du r | jj dkr |dkr ||  |S |dkr;||  | jD ]
}|t|dd7 }q.|S |dkrW| jd	 d
krU| jd } | dkrU|t| 7 }|S z| j}W n
 tyf   Y |S w | j tv rs|ss||  |D ]	}|t||7 }qu|S )z
    For static analysis.
    nameFparam=	expr_stmtT)
last_added	decorator)()typeget_next_leafparentappendchildrenget_executable_nodesAttributeError_EXECUTE_NODES)noder    resulttypZ	next_leafchildr*    r2   H/var/www/html/lang_env/lib/python3.10/site-packages/jedi/parser_utils.pyr+      s:   





r+   c                 c   sX    | V  | j d }	 |jdkr|j d V  n|jdkr|V  n|jdks&d S |j d }q
)NTcomp_for   sync_comp_forZcomp_ifr*   r&   )r5   lastr2   r2   r3   get_sync_comp_fors:   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
    r6   r   r8   )for_stmtr2   r2   r3   for_stmt_defines_one_nameG   s   r<   c                 C   sp   |j }| j |  k r| jkstd tdd }t| jD ]\}}||j k r+|  S | }|tv r5|}qd S )Nz!The node is not part of the flow.)	start_posend_pos
ValueError	enumerater*   get_first_leaf_FLOW_KEYWORDS)Z	flow_noder.   r=   keywordir1   Z
first_leafr2   r2   r3   get_flow_branch_keywordQ   s   
rE   c                 C   s"   |   }|durtt|jS dS )z3 Returns a cleaned version of the docstring token. N )Zget_doc_noder   safe_literal_evalvalue)Z
scope_noder.   r2   r2   r3   clean_scope_docstring`   s   rI   c                 C   sP   | j dkr&| j} |  }|d ur&|j dkr&|jd }|j dkr&tt|jS dS )Nr   Zsimple_stmtr   stringrF   )r&   r(   Zget_next_siblingr*   r   rG   rH   )Z	tree_nodeZmaybe_stringr2   r2   r3   find_statement_documentationl   s   



rK   c                 C   s0   | d d   }|d dks|dv rdS t| S )N   r   f)frrfrF   )lowerr   )rH   Z	first_twor2   r2   r3   rG   x   s   rG   H   c           	      C   s   |du r| j dkrd}n| jj}|  }|r|dd }dddd |D   d	 }td
d|}| jr@|s@d| j	  }nd}|| | }dt
||S )z
    Generate a string signature of a 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lambdef<lambda>r6   r%   rF   c                 s   s    | ]}|  V  qd S N)get_code).0r   r2   r2   r3   	<genexpr>   s    z get_signature.<locals>.<genexpr>r#   z\s+ z ->
)r&   r   rH   
get_paramsjoinstripresub
annotationrU   textwrapwrap)	r	   widthZcall_stringZomit_first_paramZomit_return_annotationparamspZrtypecoder2   r2   r3   get_signature   s   
 
rf   c                 C   sF   z| j }W n ty   |  j|7  _Y dS w |D ]}t|| qdS )z$
    Move the `Node` start_pos.
    N)r*   r,   linemove)r.   line_offsetr*   cr2   r2   r3   rh      s   
rh   c                 C   s   z5| j dkr| jd  j}n%| j dkr| jd  j}n| j dkr-| jd   j}n|   j}W n ty?   Y dS  tyH   Y dS w d|vrOdS ||dd }d	|v re|d|d	 }d
|v rr|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#rY   )	r&   r*   rA   prefixr'   Zget_last_leafr,   r?   index)r.   
whitespacecommentr2   r2   r3   get_following_comment_same_line   s,   


rt   c                 C   s&   | j }|dkr| jd j dkS |dv S )Nr5   r6   r7   )Z
file_inputr   r	   rR   r7   )r&   r*   )r.   tr2   r2   r3   is_scope   s   rv   c                    s   t   d fdd	}|S )NFc                    sr   | d u r	||S z |  }W n t y   i  } | < Y nw z|| W S  t y8   || }||< | Y S w rT   )KeyError)Zparso_cache_noder.   include_flowsZ
for_moduler/   cachefuncr2   r3   wrapper   s   

z(_get_parent_scope_cache.<locals>.wrapperFr   )r{   r|   r2   ry   r3   _get_parent_scope_cache   s   r~   c                    s    j }|du r	dS 	 t|rH|jdv rF|jd}|j| j jkrF j jdkr1 j j kr1	 |S  j jdkrB j jd  krB	 |S |j }q	|S |rdt|tj	rd|jdkrbt
 fd	d
| D sd|S |j }q
)z'
    Returns the underlying scope.
    NT)r   r	   rR   :r   Ztfpdefr   Zif_stmtc                 3   s.    | ]}|j  j   ko|jk n  V  qd S rT   )r=   r>   )rV   nr.   r2   r3   rW     s    &z#get_parent_scope.<locals>.<genexpr>)r(   rv   r&   r*   rq   r=   r   
isinstancer   ZFlowanyZget_test_nodes)r.   rx   scoperq   r2   r   r3   get_parent_scope   s4   

r   c                 C   s   t | |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.
    )get_parso_cache_nodelinesZgrammarpathr2   r2   r3   get_cached_code_lines  s   r   c                 C   s   t | j | S )z
    This is of course not public. But as long as I control parso, this
    shouldn't be a problem. ~ Dave

    The reason for this is mostly caching. This is obviously also a sign of a
    broken caching architecture.
    )r   Z_hashedr   r2   r2   r3   r     s   r   c                 C   sj   t | jddd|d | j d  }|d }| j|d kr"|| j8 }|s&dS |d d| |d< d|S )z3
    Cuts of the value of the leaf at position
    T)keependsNr   r6   rF   r4   )r   rH   rg   columnr[   )leafpositionr   r   r2   r2   r3   cut_value_at_position"  s   $

r   c                 C   s   | j dkrt| jdkr| jd dkrt| jd S dS | j dkrA| j}|d dkr,dS t|d s4dS td	d
 |dd D S | j dkS )zP
    Checks if a path looks like `name` or `name.foo.bar` and not `name()`.
    r
   rl   r   r%   r6   Fr   awaitc                 s   s    | ]
}|j d  dkV  qdS )r   .N)r*   )rV   rj   r2   r2   r3   rW   ?  s    z!expr_is_dotted.<locals>.<genexpr>Nr   )r&   lenr*   expr_is_dottedall)r.   r*   r2   r2   r3   r   0  s   


r   c                    s    fdd}|S )Nc                    s.   |   D ]}|jd } | r dS qdS )z
        This is a heuristic. It will not hold ALL the times, but it will be
        correct pretty much for anyone that doesn't try to beat it.
        staticmethod/classmethod are builtins and unless overwritten, this will
        be correct.
        r6   TF)Zget_decoratorsr*   rU   )Zfunction_noder!   Zdotted_namedecorator_checkerr2   r3   r|   D  s   
z&_function_is_x_method.<locals>.wrapperr2   )r   r|   r2   r   r3   _function_is_x_methodC  s   r   c                 C      | dkS )Nstaticmethodr2   mr2   r2   r3   <lambda>S      rS   c                 C   r   )Nclassmethodr2   r   r2   r2   r3   r   T  r   c                 C   s   | dkp| dkp|  dS )Npropertycached_propertyz.setter)endswithr   r2   r2   r3   r   V  s    
r}   )rQ   NFF)&r]   r`   astr   inspectr   weakrefr   Zparso.pythonr   Zparso.cacher   Zparsor   r-   rB   r+   r:   r<   rE   rI   rK   rG   rf   rh   rt   rv   r~   r   Zget_cached_parent_scoper   r   r   r   r   Zfunction_is_staticmethodZfunction_is_classmethodZfunction_is_propertyr2   r2   r2   r3   <module>   sH    
%


!	
 