o
    ˷e!                     @   s2  d dl Z 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
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 Zdd Zdd Zdd Zd/ddZdd Zdd Zd/ddZdd Zdd Zdd Z d d! Z!d0d#d$Z"d1d%d&Z#d'd( Z$d)d* Z%d+d, Z&G d-d. d.Z'dS )2    N)Path)ZipFile)zipimporterZipImportError)all_suffixes)access)debug)parser_utils)KnownContentFileIO	ZipFileIOc                   C      t jS N)syspath r   r   c/var/www/ideatree/venv/lib/python3.10/site-packages/jedi/inference/compiled/subprocess/functions.pyget_sys_path      r   c                 K   s   t j| fi |S r   )r   load_module)inference_statekwargsr   r   r   r         r   c                 O   s"   | j |}t|j||i |S r   )compiled_subprocessget_access_handlegetattrr   )r   id	attributeargsr   handler   r   r   get_compiled_method_return   s   r   c                 C   s   t | |S r   )r   create_access_path)r   objr   r   r   create_simple_object   s   r"   c                 K   sx   |dur|t jt _}z(ztdd|i|W W |dur|t _S S  ty3   Y W |dur1|t _dS dS w |dur;|t _w )zK
    Returns Tuple[Union[NamespaceInfo, FileIO, None], Optional[bool]]
    N	full_nameNNr   )r   r   _find_moduleImportError)r   sys_pathr#   r   tempr   r   r   get_module_info"   s   
r)   c                 C   r   r   )r   builtin_module_names)r   r   r   r   get_builtin_module_names1   r   r+   c                 C   s   |)zE
    Raise an error to simulate certain problems for unit tests.
    r   )r   exception_typer   r   r   _test_raise_error5   s   r-   c                 C   sB   |durt |tjd tj  |durt | tj  dS dS )zL
    Force some prints in the subprocesses. This exists for unit tests.
    N)file)printr   stderrflushstdout)r   r0   r2   r   r   r   _test_print<   s   
r3   c                 C   s6   t  D ]}tj| d| }tj|r|  S qdS )z^
    The __init__ file can be searched in a directory. If found return it, else
    None.
    __init__N)r   osr   joinexists)directory_pathsuffixr   r   r   r   _get_init_pathH   s   
r:   c                 C   s
   t |S r   )r	   safe_literal_eval)r   valuer   r   r   r;   T   s   
r;   c                  O   s   t t| i |S r   )list_iter_module_names)r   r   r   r   r   iter_module_namesX   r   r?   c                 c   s    |D ]i}zdd t |D }W n' ty8   zt|}t|j|j}W n ty5   t	d| Y Y qw Y nw |D ]0\}}|rM|dkrL|
 rL|V  q;|drY|d d }nt|}|rkd|vrk|dkrk|V  q;qd S )	Nc                 s   s    | ]
}|j | fV  qd S r   )nameis_dir).0entryr   r   r   	<genexpr>`   s    z%_iter_module_names.<locals>.<genexpr>z"Not possible to list directory: %s__pycache__z.pyi.r4   )r5   scandirOSErrorr   _zip_list_subdirectoryarchiveprefixr   r   warningisidentifierendswithinspectgetmodulename)r   pathsr   dir_entrieszip_import_infor@   rA   modnamer   r   r   r>   \   s<   

r>   Tc           
   	   C   s   d}d}t jD ]F}|r|tjjkrd}n|}z|j}W n	 ty$   Y qw || |}|durM|j}|du rK|jsK|s<| n|}t	||j
j}	|	df  S  nqt| ||S )a  
    Provides information about a module.

    This function isolates the differences in importing libraries introduced with
    python 3.3 on; it gets a module name and optionally a path. It will return a
    tuple containin an open file for the module (if not builtin), the filename
    or the name of the module if it is a builtin one and a boolean indicating
    if the module is contained in a package.
    NT)r   	meta_path	importlib	machinery
PathFinder	find_specAttributeErrorloaderhas_locationImplicitNSInfosubmodule_search_locations_path_find_module_py33)
stringr   r#   is_global_searchspecr\   finderprZ   implicit_ns_infor   r   r   r%      s*   



	r%   c              
   C   s   |p	t jj| |}|d u rD|d u rDztjdd t | }W d    n1 s)w   Y  W n tyC } ztdt	| d }~ww |d u rOtd
| t|| S )NT)recordzOriginally  zCouldn't find a loader for {})rW   rX   rY   find_modulewarningscatch_warningsfind_loader
ValueErrorr&   reprformat_from_loader)rb   r   r\   r#   rc   er   r   r   ra      s   
ra   c                 C   s   z| j }W n ty   d}Y nw ||}z| j}W n ty'   d |f Y S w ||}zt| j}W n ty>   tdw |tjjjurL| |}nt	| |}|d u rYd |fS t
| trit||t| j|fS t|||fS )NFz$get_source was not defined on loader)
is_packager[   get_filenametype
get_sourcer&   rW   rX   SourceFileLoader_get_source
isinstancer   r   r   rK   r
   )r\   rb   is_package_methodrr   rs   module_pathfcoder   r   r   rp      s2   



rp   c                 C   s2   |  |}z| |W S  ty   td|dw )z
    This method is here as a replacement for SourceLoader.get_source. That
    method returns unicode, but we prefer bytes.
    z'source not available through get_data())r@   )rs   get_datarI   r&   )r\   fullnamer   r   r   r   rw      s   
rw   c                 c   sV    t | }t|}| }|D ]}t|}|j|kr(||}|j|dfV  qd S )N/)r   r   namelistparentrelative_tor@   rO   )zip_pathzip_subdir_pathzip_filezip_content_file_pathsraw_file_name	file_pathr   r   r   rJ      s   

rJ   c                   @   s   e Zd ZdZdd ZdS )r^   z;Stores information returned from an implicit namespace specc                 C   s   || _ || _d S r   )r@   rR   )selfr@   rR   r   r   r   r4      s   
zImplicitNSInfo.__init__N)__name__
__module____qualname____doc__r4   r   r   r   r   r^      s    r^   r$   )NNT)NNNT)(r   r5   rP   rW   rj   pathlibr   zipfiler   	zipimportr   r   importlib.machineryr   jedi.inference.compiledr   jedir   r	   jedi.file_ior
   r   r   r   r   r"   r)   r+   r-   r3   r:   r;   r?   r>   r%   ra   rp   rw   rJ   r^   r   r   r   r   <module>   s>    


#
&'