o
    b*                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZzd dlZdZ	W n e
y/   dZ	Y nw zd dlmZ W n e
yG   d dlmZ Y nw ddlmZ eddZejejejejejejejejejejejejiZeed	ryejeej< eed
rejeej< dd ZeddZG dd deZG dd dZ G dd de Z!G dd de!Z"G dd de Z#G dd de Z$e!e#fZ%e	rej&dd dkre%e$f7 Z%e%e"f7 Z%dd Z'e dd  Z(d)d!d"Z)d#d$ Z*d%d& Z+d)d'd(Z,dS )*    NTF)	lru_cache   )util
ModuleTypezyC_BUILTIN C_EXTENSION PKG_DIRECTORY PY_CODERESOURCE PY_COMPILED PY_FROZEN PY_RESOURCE PY_SOURCE PY_ZIPMODULE PY_NAMESPACEPY_RESOURCEPY_CODERESOURCEc                 C   s   t |  S N)	_ImpTypes)Zimp_type r
   _/var/www/secure340b-portal/env/lib/python3.10/site-packages/astroid/interpreter/_import/spec.py_imp_type_to_module_type3   s   r   _ModuleSpecz4name type location origin submodule_search_locationsc                   @   s    e Zd ZdZ			dddZdS )
ModuleSpeczDefines a class similar to PEP 420's ModuleSpec

    A module spec defines a name of a module, its type, location
    and where submodules can be found, if the module is a package.
    Nc                 C   s   t j| |||||dS )N)nametypelocationoriginsubmodule_search_locations)r   __new__)clsr   module_typer   r   r   r
   r
   r   r   C   s   zModuleSpec.__new__)NNN)__name__
__module____qualname____doc__r   r
   r
   r
   r   r   <   s    
r   c                   @   s0   e Zd ZdZd	ddZejdd Zdd ZdS )
Finderz@A finder is a class which knows how to find a particular module.Nc                 C   s   |pt j| _d S r   )syspath_pathselfr   r
   r
   r   __init__X   s   zFinder.__init__c                 C      dS )a  Find the given module

        Each finder is responsible for each protocol of finding, as long as
        they all return a ModuleSpec.

        :param str modname: The module which needs to be searched.
        :param list module_parts: It should be a list of strings,
                                  where each part contributes to the module's
                                  namespace.
        :param list processed: What parts from the module parts were processed
                               so far.
        :param list submodule_path: A list of paths where the module
                                    can be looked into.
        :returns: A ModuleSpec, describing how and where the module was found,
                  None, otherwise.
        Nr
   r    modnamemodule_parts	processedsubmodule_pathr
   r
   r   find_module[       zFinder.find_modulec                 C   r"   )z7Get a list of extra paths where this finder can search.Nr
   r    specr&   r
   r
   r   contribute_to_pathn   r)   zFinder.contribute_to_pathr   )	r   r   r   r   r!   abcabstractmethodr(   r,   r
   r
   r
   r   r   U   s    

r   c                   @       e Zd ZdZdd Zdd ZdS )	ImpFinderz!A finder based on the imp module.c                 C   s^   |d urt |}zt||\}}}W n
 ty   Y d S w |r$|  t||t|d dS )N   )r   r   r   )listimpr(   ImportErrorcloser   r   )r    r$   r%   r&   r'   streamZmp_filenameZmp_descr
   r
   r   r(   u   s   
zImpFinder.find_modulec                    s<   |j d u rd S t|j r fddtjD }|S |j g}|S )Nc                    s<   g | ]}t jt jj|g R  rt jj|g R  qS r
   )osr   isdirjoin).0pr&   r
   r   
<listcomp>   s    z0ImpFinder.contribute_to_path.<locals>.<listcomp>)r   _is_setuptools_namespacer   r   )r    r+   r&   r   r
   r<   r   r,      s   


zImpFinder.contribute_to_pathNr   r   r   r   r(   r,   r
   r
   r
   r   r0   r       r0   c                   @   r/   )ExplicitNamespacePackageFinderzNA finder for the explicit namespace packages, generated through pkg_resources.c                 C   sL   |r
d ||g }t|r$|tjv r$tj| j}t|ddtj|dS d S )N. 	namespacer   r   r   r   r   )	r9   r   is_namespacer   modules__path__r   r   PY_NAMESPACEr#   r
   r
   r   r(      s   z*ExplicitNamespacePackageFinder.find_modulec                 C   s   |j S r   r   r*   r
   r
   r   r,      s   z1ExplicitNamespacePackageFinder.contribute_to_pathNr?   r
   r
   r
   r   rA      s    rA   c                       s(   e Zd ZdZ fddZdd Z  ZS )	ZipFinderz8Finder that knows how to find a module inside zip files.c                    s   t t| | t|| _d S r   )superrK   r!   _precache_zipimporters_zipimportersr   	__class__r
   r   r!      s   zZipFinder.__init__c                 C   s>   zt || j\}}}W n
 ty   Y d S w t||d||dS )NeggrE   )_search_ziprN   r4   r   )r    r$   r%   r&   r'   	file_typefilenamer   r
   r
   r   r(      s   zZipFinder.find_module)r   r   r   r   r!   r(   __classcell__r
   r
   rO   r   rK      s    rK   c                   @   r/   )PathSpecFinderz/Finder based on importlib.machinery.PathFinder.c           	      C   s`   t jjj||d}|r.|jdv }|s|jnd }|rtjnd }t|j||j|t	|j
p*g d}|S )N)r   )rD   NrE   )	importlib	machinery
PathFinder	find_specr   r   rI   r   r   r2   r   )	r    r$   r%   r&   r'   r+   Zis_namespace_pkgr   r   r
   r
   r   r(      s   
zPathSpecFinder.find_modulec                 C   s   |j tjkr	|jS d S r   )r   r   rI   r   r*   r
   r
   r   r,      s   z!PathSpecFinder.contribute_to_pathNr?   r
   r
   r
   r   rV      r@   rV   r1   )      c                 C   s   z!t tj| dd}|d}W d    n1 sw   Y  W n
 ty+   Y d S w d|v o3d|v }d|v o;d|v }|p?|S )Nz__init__.pyrbi   s   pkgutils   extend_paths   pkg_resourcess   declare_namespace(__name__))openr7   r   r9   readIOError)r   r6   dataextend_pathdeclare_namespacer
   r
   r   r>      s   r>   c                 C   s   t | }|| |S r   )setdifference_update)leftrightresultr
   r
   r   _cached_set_diff   s   
ri   c              	   C   sZ   t j}t| pt j}t|}t||}|D ]}z	t|||< W q tjy*   Y qw |S r   )r   path_importer_cachetupler   ri   	zipimportzipimporterZipImportError)r   picZ	req_pathsZcached_pathsZ	new_paths
entry_pathr
   r
   r   rM      s   
rM   c                 C   s   t | D ]B\}}|d urH|| d }|rH|tjj| s1tdd| dd  || f tj	tj
|tjj tjj|  |f  S qtdd|  )Nr   zNo module named %s in %s/%srB   r   No module named %s)r2   itemsr(   r7   r   sepr9   r4   r   ZPY_ZIPMODULEabspath)modpathro   filepathimporterfoundr
   r
   r   rR     s     rR   c                    sR    fddt D }|D ]}|||||}|d u rq||f  S tdd| )Nc                    s   g | ]}| qS r
   r
   )r:   findersearch_pathr
   r   r=   !  s    z(_find_spec_with_path.<locals>.<listcomp>rq   rB   )_SPEC_FINDERSr(   r4   r9   )r{   r$   r%   r&   r'   Zfindersry   r+   r
   rz   r   _find_spec_with_path   s   r}   c           	      C   s   |pt j}| dd } d}| dd }g }| rC| d}t|||||p$|\}}|| | r5|||}|jtjkrA|j	|d}| s|S )a  Find a spec for the given module.

    :type modpath: list or tuple
    :param modpath:
      split module's name (i.e name of a module or package split
      on '.'), with leading empty strings for explicit relative import

    :type path: list or None
    :param path:
      optional list of path where the module or package should be
      searched (use sys.path if nothing or None is given)

    :rtype: ModuleSpec
    :return: A module spec, which describes how the module was
             found and where.
    Nr   rJ   )
r   r   popr}   appendr,   r   r   PKG_DIRECTORY_replace)	ru   r   r   r'   r%   r&   r$   ry   r+   r
   r
   r   rZ   +  s"   


rZ   r   )-r-   collectionsenumr3   r7   r   rl   Zimportlib.machineryrW   Z_HAS_MACHINERYr4   	functoolsr   Zbackports.functools_lru_cacherC   r   Enumr   Z	C_BUILTINC_EXTENSIONr   PY_COMPILEDZ	PY_FROZEN	PY_SOURCEr	   hasattrr   r   r   
namedtupler   r   r   r0   rA   rK   rV   r|   version_infor>   ri   rM   rR   r}   rZ   r
   r
   r
   r   <module>   sn   

'



