o
    ˷e*                     @   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"d0Z#e"d1Z$e"d2d3Z%dS )6    N)literal_eval)cleandocWeakKeyDictionary)tree)parser_cache)split_lines>   atomexprtermtestpowerfactorfuncdefor_testand_exprand_testclassdefnot_testxor_expr	atom_expr
arith_expr
comparison
shift_exprimport_fromimport_name)	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typ	next_leafchildr3    r<   H/var/www/ideatree/venv/lib/python3.10/site-packages/jedi/parser_utils.pyr4      s:   





r4   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_forcomp_ifr3   r/   )r?   lastr<   r<   r=   get_sync_comp_fors:   s   




rE   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%   rC   )for_stmtr<   r<   r=   for_stmt_defines_one_nameG   s   rG   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	enumerater3   get_first_leaf_FLOW_KEYWORDS)	flow_noder7   rH   keywordir;   
first_leafr<   r<   r=   get_flow_branch_keywordQ   s   
rR   c                 C   s"   |   }|durtt|jS dS )z3 Returns a cleaned version of the docstring token. N )get_doc_noder   safe_literal_evalvalue)
scope_noder7   r<   r<   r=   clean_scope_docstring`   s   rX   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(   simple_stmtr   stringrS   )r/   r1   get_next_siblingr3   r   rU   rV   )	tree_nodemaybe_stringr<   r<   r=   find_statement_documentationl   s   



r^   c                 C   s0   | d d   }|d dks|dv rdS t| S )N   r   f)frrfrS   )lowerr   )rV   	first_twor<   r<   r=   rU   x   s   rU   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lambdefz<lambda>r@   r.   rS   c                 s   s    | ]}|  V  qd S N)get_code).0r&   r<   r<   r=   	<genexpr>   s    z get_signature.<locals>.<genexpr>r,   z\s+ z ->
)r/   r%   rV   
get_paramsjoinstripresub
annotationrh   textwrapwrap)	r   widthcall_stringomit_first_paramomit_return_annotationparamsprtypecoder<   r<   r=   get_signature   s   
 
r}   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)r3   r5   linemove)r7   line_offsetr3   cr<   r<   r=   r      s   
r   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 #
    rF      	with_stmt   r      N#rl   )	r/   r3   rL   prefixr0   get_last_leafr5   rJ   index)r7   
whitespacecommentr<   r<   r=   get_following_comment_same_line   s,   


r   c                 C   s&   | j }|dkr| jd j dkS |dv S )Nr?   r@   rA   )
file_inputr   r   rf   rA   )r/   r3   )r7   tr<   r<   r=   is_scope   s   r   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 rg   )KeyError)parso_cache_noder7   include_flows
for_moduler8   cachefuncr<   r=   wrapper   s   

z(_get_parent_scope_cache.<locals>.wrapperFr   )r   r   r<   r   r=   _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   rf   :r&   tfpdefr   if_stmtc                 3   s.    | ]}|j  j   ko|jk n  V  qd S rg   )rH   rI   )ri   nr7   r<   r=   rj     s    &z#get_parent_scope.<locals>.<genexpr>)r1   r   r/   r3   r   rH   r%   
isinstancer   Flowanyget_test_nodes)r7   r   scoper   r<   r   r=   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grammarpathr<   r<   r=   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   _hashedr   r<   r<   r=   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   r@   rS   r>   )r   rV   r~   columnrn   )leafpositionr   r   r<   r<   r=   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	   r   r   r.   r@   Fr   awaitc                 s   s    | ]
}|j d  dkV  qdS )r   .N)r3   )ri   r   r<   r<   r=   rj   ?  s    z!expr_is_dotted.<locals>.<genexpr>Nr%   )r/   lenr3   expr_is_dottedall)r7   r3   r<   r<   r=   r   0  s   


r   c                     s    fdd}|S )Nc                    s.   |   D ]}|jd }|  v 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.
        r@   TF)get_decoratorsr3   rh   )function_noder*   dotted_namemethod_namesr<   r=   r   D  s   
z&_function_is_x_method.<locals>.wrapperr<   )r   r   r<   r   r=   _function_is_x_methodC  s   r   staticmethodclassmethodpropertycached_propertyr   )re   NFF)&rp   rs   astr   inspectr   weakrefr   parso.pythonr   parso.cacher   parsor   r6   rM   r4   rE   rG   rR   rX   r^   rU   r}   r   r   r   r   r   get_cached_parent_scoper   r   r   r   r   function_is_staticmethodfunction_is_classmethodfunction_is_propertyr<   r<   r<   r=   <module>   sD    
%


!	
 