a
    lc!                     @   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d0ddZdd Zdd Zdd Z d d! Z!d1d#d$Z"d2d%d&Z#d'd( Z$d)d* Z%d+d, Z&G d-d. d.Z'dS )3    N)Path)ZipFile)zipimporterZipImportError)all_suffixes)access)debug)parser_utils)KnownContentFileIO	ZipFileIOc                   C   s   t jS N)syspath r   r   h/var/www/html/django/DPS/env/lib/python3.9/site-packages/jedi/inference/compiled/subprocess/functions.pyget_sys_path   s    r   c                 K   s   t j| fi |S r   )r   load_module)inference_statekwargsr   r   r   r      s    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   s   |dur|t j t _}z\z$tf d|i|W W |dur<|t _S  ty`   Y W |dur\|t _dS 0 W |dur|t _n|dur|t _0 dS )zK
    Returns Tuple[Union[NamespaceInfo, FileIO, None], Optional[bool]]
    N	full_name)NN)r   r   _find_moduleImportError)r   sys_pathr   r   tempr   r   r   get_module_info"   s     r"   c                 C   s   t jS r   )r   builtin_module_names)r   r   r   r   get_builtin_module_names1   s    r$   c                 C   s   |dS )zE
    Raise an error to simulate certain problems for unit tests.
    Nr   )r   Zexception_typer   r   r   _test_raise_error5   s    r%   c                 C   s>   |dur t |tjd tj  |dur:t | tj  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_pathH   s
    

r1   c                 C   s
   t |S r   )r	   safe_literal_eval)r   valuer   r   r   r2   T   s    r2   c                  O   s   t t| i |S r   )list_iter_module_names)r   r   r   r   r   iter_module_namesX   s    r6   c                 c   s   |D ]}zdd t |D }W nR tyr   zt|}t|j|j}W n$ tyl   t	d| Y Y qY n0 Y n0 |D ]`\}}|r|dkr|
 r|V  qx|dr|d d }n
t|}|rxd|vrx|dkrx|V  qxqd S )	Nc                 s   s   | ]}|j | fV  qd S r   )nameis_dir).0entryr   r   r   	<genexpr>`       z%_iter_module_names.<locals>.<genexpr>z"Not possible to list directory: %s__pycache__z.pyi.r,   )r-   scandirOSErrorr   _zip_list_subdirectoryarchiveprefixr   r   warningisidentifierendswithinspectgetmodulename)r   pathsr   Zdir_entriesZzip_import_infor7   r8   modnamer   r   r   r5   \   s,    

r5   Tc           
   	   C   s   d}d}t jD ]}|r(|tjjkr(d}n|}z
|j}W n tyL   Y qY n0 || |}|dur|j}|du r|js|s|| n|}t	||j
j}	|	df  S  qq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specrR   finderprP   Zimplicit_ns_infor   r   r   r      s&    




r   c              
   C   s   |pt jj| |}|d u r|d u rz:tjdd t | }W d    n1 sR0    Y  W n4 ty } ztdt	| W Y d }~n
d }~0 0 |d u rtd
| t|| S )NT)recordzOriginally  zCouldn't find a loader for {})rM   rN   rO   find_modulewarningscatch_warningsfind_loader
ValueErrorr   reprformat_from_loader)rX   r   rR   r   rY   er   r   r   rW      s    ,&rW   c                 C   s   z
| j }W n ty    d}Y n
0 ||}z
| j}W n tyN   d |f Y S 0 ||}zt| j}W n ty   tdY n0 |tjjjur| |}n
t	| |}|d u rd |fS t
| trt||t| j|fS t|||fS )NFz$get_source was not defined on loader)
is_packagerQ   get_filenametype
get_sourcer   rM   rN   SourceFileLoader_get_source
isinstancer   r   r   rC   r
   )rR   rX   Zis_package_methodrg   rh   module_pathfcoder   r   r   re      s,    




re   c                 C   s:   |  |}z| |W S  ty4   td|dY n0 dS )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())r7   N)rh   get_datarA   r   )rR   fullnamer   r   r   r   rl      s    
rl   c                 c   sT   t | }t|}| }|D ]2}t|}|j|kr||}|j|dfV  qd S )N/)r   r   namelistparentrelative_tor7   rG   )zip_pathZzip_subdir_pathzip_fileZzip_content_file_pathsZraw_file_name	file_pathr   r   r   rB      s    

rB   c                   @   s   e Zd ZdZdd ZdS )rT   z;Stores information returned from an implicit namespace specc                 C   s   || _ || _d S r   )r7   rJ   )selfr7   rJ   r   r   r   r,      s    zImplicitNSInfo.__init__N)__name__
__module____qualname____doc__r,   r   r   r   r   rT      s   rT   )NN)NN)NNT)NNNT)(r   r-   rH   rM   r_   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+   r1   r2   r6   r5   r   rW   re   rl   rB   rT   r   r   r   r   <module>   s<   

#
&
'