U
    -e7                     @   s   d dl Z d dlZ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 Z
dd Zd$d
dZdd Zdd Zdd Zdd Zdd Zdd Zdd ZG dd deZedd Zd%ddZd d! Zd"d# ZdS )&    N)chain)contextmanager)treec                 C   sJ   | j }d|ksd|krdS tjtjdd}ttt	|d t
| S )Nzdist-packageszsite-packagesFlibpythonz\d.\d)partsospathjoinsysprefixboolrematchescapestr)r	   r   	base_path r   W/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/jedi/inference/helpers.pyis_stdlib_path   s
    r   c                 C   sZ   t  | }g }| jD ]:}t|tjr6t  |}||_nt|}||_|| q||_|S )zO
    Much, much faster than copy.deepcopy, but just for parser tree nodes.
    )copychildren
isinstancer   ZLeafparentdeep_ast_copyappend)objZnew_objZnew_childrenchild	new_childr   r   r   r      s    


r   Fc                 C   sN  |j }|jdkr(ddlm} || jS |jdksJ||jd |jd fkr|dkrbddlm} |S |jdkrv| 	|S | 	|S |j }|j
|}|r|}n|d	 }|jd
kr|}	|	d	8 }	|j|	 }
|
jdkrqq|j|	d	 | }n|jd }
|jd	| }|
dkr|d }
|d	d }| 	|
}ddlm} |D ]}|| ||}q6|S )a  
    Creates a "call" node that consist of all ``trailer`` and ``power``
    objects.  E.g. if you call it with ``append``::

        list([]).append(3) or None

    You would get a node with the content ``list([]).append`` back.

    This generates a copy of the original ast node.

    If you're using the leaf, e.g. the bracket `)` it will return ``list([])``.

    We use this function for two purposes. Given an expression ``bar.foo``,
    we may want to
      - infer the type of ``foo`` to offer completions after foo
      - infer the type of ``bar`` to be able to jump to the definition of foo
    The option ``cut_own_trailer`` must be set to true for the second purpose.
    Zfstringr   )compiledtrailer:)	NO_VALUESZatom   Z
error_nodeawaitN)infer_trailer)r   typeZjedi.inferencer   Zget_string_value_setinference_stater   Zjedi.inference.base_valuer#   Z
infer_nodeindexZjedi.inference.syntax_treer&   )contextleafZcut_own_trailerr    r   r#   powerr)   cutstartbaseZtrailersvaluesr&   r   r   r   infer_call_of_leaf-   sB    
"








r1   c                 C   sX   z
| j }W n0 tk
r:   | jdkr.| g Y S g  Y S Y nX ttdd |D S d S )Nnamec                 s   s   | ]}t |V  qd S N)get_names_of_node).0cr   r   r   	<genexpr>x   s     z$get_names_of_node.<locals>.<genexpr>)r   AttributeErrorr'   listr   from_iterable)noder   r   r   r   r4   o   s    


r4   c                 C   s   |   ot| jd dtS N)default)Zis_compiledr   get_safe_valuer   valuer   r   r   	is_string{   s    rA   c                 C   s   t | pt| S r3   )	is_numberrA   r?   r   r   r   
is_literal   s    rC   c                 C   s   | j d d} t| |r| S d S r<   )r>   r   )r@   acceptr   r   r   _get_safe_value_or_none   s    
rE   c                 C   s
   t | tS r3   )rE   intr?   r   r   r   get_int_or_none   s    rG   c                 C   s
   t | tS r3   )rE   r   r?   r   r   r   get_str_or_none   s    rH   c                 C   s   t | ttfd k	S r3   )rE   rF   floatr?   r   r   r   rB      s    rB   c                   @   s   e Zd ZdS )SimpleGetItemNotFoundN)__name__
__module____qualname__r   r   r   r   rJ      s   rJ   c               
   g   s:   z
d V  W n* | k
r4 } zt |W 5 d }~X Y nX d S r3   )rJ   )Zexception_classeser   r   r   reraise_getitem_errors   s    
rO   c                 C   s   d}g }| dd  D ]}|dkr4|s|t |j7 }q|jdkrr|jd d d D ]}|| ||krN qlqNq qq|jdkr|| ||kr qq|dkr|sg }q qq||fS )Nr   r$   ).z...Zdotted_name   r2   ,)lenr@   r'   r   r   )ZnodesZis_import_fromZ
until_nodelevelnamesr;   nr   r   r   parse_dotted_names   s,    



rW   c                 G   s   |  |d d |d S )Nr!   )import_moduleZpy__getattribute__)r(   rU   r   r   r   values_from_qualified_names   s    rY   c                 C   s"   |   j}|d krdS |d dkS )NFr   )ZpandasnumpyZ
tensorflowZ
matplotlib)Zget_root_contextstring_names)r*   r[   r   r   r   is_big_annoying_library   s    
r\   )F)N)r   r   r   r   	itertoolsr   
contextlibr   Zparso.pythonr   r   r   r1   r4   rA   rC   rE   rG   rH   rB   	ExceptionrJ   rO   rW   rY   r\   r   r   r   r   <module>   s,   
B

