o
    Zh!                     @   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	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/html/lang_env/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   )Zcompiled_subprocessZget_access_handlegetattrr   )r   id	attributeargsr   handler   r   r   get_compiled_method_return   s   r   c                 C   s   t | |S r   )r   Z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_names0   r   r(   c                 C   s   |)zE
    Raise an error to simulate certain problems for unit tests.
    r   )r   Zexception_typer   r   r   _test_raise_error4   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   r,   r.   r   r   r   _test_print;   s   
r/   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)Zdirectory_pathsuffixr   r   r   r   _get_init_pathG   s   
r5   c                 C   s
   t |S r   )r	   safe_literal_eval)r   valuer   r   r   r6   S   s   
r6   c                  O   s   t t| i |S r   )list_iter_module_names)r   r   r   r   r   iter_module_namesW   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.r0   )r1   scandirOSErrorr   _zip_list_subdirectoryarchiveprefixr   r   warningisidentifierendswithinspectgetmodulename)r   pathsr   Zdir_entriesZzip_import_infor;   r<   modnamer   r   r   r9   [   s<   

r9   Tc           
   	   C   s   d}d}t jD ]L}|r|tjjkrd}n|}z|j}W n	 ty$   Y qw || |}|durS|jdkr4q|j}|du rQ|j	sQ|sB| 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.
    NfrozenT)r   	meta_path	importlib	machinery
PathFinder	find_specAttributeErrororiginloaderhas_locationImplicitNSInfosubmodule_search_locations_path_find_module_py33)
stringr   r    is_global_searchspecrW   finderprT   Zimplicit_ns_infor   r   r   r"   ~   s.   




r"   c              
   C   s   |st jj| |}|d ur|j}|d u r=|d u r=zt j| }|d ur'|j}W n ty< } ztdt| d }~ww |d u rHtd	| t
|| S )NzOriginally  zCouldn't find a loader for {})rQ   rR   rS   rT   rW   util
ValueErrorr#   reprformat_from_loader)r]   r   rW   r    r^   r_   er   r   r   r\      s"   
r\   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_packagerU   get_filenametype
get_sourcer#   rQ   rR   SourceFileLoader_get_source
isinstancer   r   r   rF   r
   )rW   r]   Zis_package_methodrh   ri   module_pathfcoder   r   r   rf      s2   



rf   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;   )ri   get_datarD   r#   )rW   fullnamer   r   r   r   rm      s   
rm   c                 c   sV    t | }t|}| }|D ]}t|}|j|kr(||}|j|dfV  qd S )N/)r   r   namelistparentrelative_tor;   rJ   )zip_pathZzip_subdir_pathzip_fileZzip_content_file_pathsZraw_file_name	file_pathr   r   r   rE      s   

rE   c                   @   s   e Zd ZdZdd ZdS )rY   z;Stores information returned from an implicit namespace specc                 C   s   || _ || _d S r   )r;   rM   )selfr;   rM   r   r   r   r0      s   
zImplicitNSInfo.__init__N)__name__
__module____qualname____doc__r0   r   r   r   r   rY      s    rY   r!   )NNT)NNNT)'r   r1   rK   rQ   pathlibr   zipfiler   	zipimportr   r   Zimportlib.machineryr   Zjedi.inference.compiledr   Zjedir   r	   Zjedi.file_ior
   r   r   r   r   r   r&   r(   r)   r/   r5   r6   r:   r9   r"   r\   rf   rm   rE   rY   r   r   r   r   <module>   s<    


#
*'