
    c5                       d dl m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d dlZd dl	Z	d dl
Z
d dlmZ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 e	j        d
k    rd dlmZ nd dlmZ  G d dej                  Z G d de          Z G d d          Z G d de          Z G d de          Z  G d de          Z! G d de          Z"ee!e"e fZ#d1dZ$d2d Z%d3d$Z&d4d.Z'd5d6d0Z(dS )7    )annotationsN)IteratorSequence)Path)Any
NamedTuple)
PY310_PLUS)EXT_LIB_DIRS   )util)      )Literalc                  >   e Zd ZdZ ej                    Z ej                    Z ej                    Z ej                    Z	 ej                    Z
 ej                    Z ej                    Z ej                    Z ej                    Z ej                    ZdS )
ModuleTypez(Python module types used for ModuleSpec.N)__name__
__module____qualname____doc__enumauto	C_BUILTINC_EXTENSIONPKG_DIRECTORYPY_CODERESOURCEPY_COMPILED	PY_FROZENPY_RESOURCE	PY_SOURCEPY_ZIPMODULEPY_NAMESPACE     @lib/python3.11/site-packages/astroid/interpreter/_import/spec.pyr   r      s        22	I$)++KDIKKMdikkO$)++K	I$)++K	I49;;L49;;LLLr#   r   c                  R    e Zd ZU dZded<   ded<   dZded<   dZded	<   dZd
ed<   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.
    strnamezModuleType | NonetypeNz
str | NonelocationoriginSequence[str] | Nonesubmodule_search_locations)r   r   r   r   __annotations__r*   r+   r-   r"   r#   r$   r&   r&   .   sg           IIIHF7;;;;;;;r#   r&   c                  F    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.Npathr,   returnNonec                ,    |pt           j        | _        d S N)sysr1   _path)selfr1   s     r$   __init__zFinder.__init__?   s    %SX


r#   modnamer'   module_partsSequence[str]	processed	list[str]submodule_pathModuleSpec | Nonec                    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 modname: The module which needs to be searched.
        :param module_parts: It should be a list of strings,
                                  where each part contributes to the module's
                                  namespace.
        :param processed: What parts from the module parts were processed
                               so far.
        :param 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"   r8   r:   r;   r=   r?   s        r$   find_modulezFinder.find_moduleB         r#   specr&   c                    dS )z7Get a list of extra paths where this finder can search.Nr"   r8   rE   r=   s      r$   contribute_to_pathzFinder.contribute_to_path[   rD   r#   r5   )r1   r,   r2   r3   
r:   r'   r;   r<   r=   r>   r?   r,   r2   r@   rE   r&   r=   r>   r2   r,   )	r   r   r   r   r9   abcabstractmethodrC   rH   r"   r#   r$   r0   r0   <   sq        JJ& & & & & 	   0F F F F F Fr#   r0   c                      e Zd ZU dZd ej        j        D             d ej        j        D             z   d ej        j        D             z   Z	de
d<   ddZddZdS )ImportlibFinderz'A finder based on the importlib module.c                *    g | ]}|t           j        fS r"   )r   r   .0ss     r$   
<listcomp>zImportlibFinder.<listcomp>e   s     UUU!Z#	$UUUr#   c                *    g | ]}|t           j        fS r"   )r   r   rP   s     r$   rS   zImportlibFinder.<listcomp>f   s     
R
R
RAz#$
R
R
Rr#   c                *    g | ]}|t           j        fS r"   )r   r   rP   s     r$   rS   zImportlibFinder.<listcomp>g   s     
V
V
V1Az%&
V
V
Vr#   z Sequence[tuple[str, ModuleType]]	_SUFFIXESr:   r'   r;   r<   r=   r>   r?   r,   r2   r@   c                   |t          |          }n|t          j        v rt          |d t          j                  S 	 t          j                            |          }|rH|j	        t          j
        j        u r0t          |t          |j        dd           t          j                  S n# t          $ r Y nw xY wt          j        }|D ]}t"          j                            ||          }dt          j
        j        d         fD ]f}d|z   }	t"          j                            ||	          }
t"          j                            |
          r t          ||t          j                  c c S gt,          j        D ]_\  }}||z   }t"          j                            ||          }
t"          j                            |
          rt          ||
|          c c S `d S )N)r(   r*   r)   filenamez.pyr   r9   )listr6   builtin_module_namesr&   r   r   	importlibr   	find_specloader	machineryFrozenImportergetattrloader_stater   
ValueErrorr1   osjoinBYTECODE_SUFFIXESisfiler   rN   rV   )r8   r:   r;   r=   r?   rE   entrypackage_directorysuffixpackage_file_name	file_pathtype_	file_names                r$   rC   zImportlibFinder.find_modulej   s!     	&!.11NN00 	&)    ~//88![I,?,NN &$!():J!M!M'1   
     XN# 	T 	TE "UG < < )"5"G"JK  $.$7!GLL):<MNN	7>>),, %$!2'5        "1!: T T#f,	GLL	::	7>>),, T%7YUSSSSSSSSTT
 ts   A(B( (
B54B5rE   r&   c                   j         d S t          t          j                             rfdt          j        D             }nj        dk    r{t          fdt          D                       s[t          j	        
                    d          }|r1|j        r*t          |j                  }t          |j                  g}nj         g}nj         g}|S )Nc                    g | ]M}t           j                            t          j        j        |gR            6t          j        j        |gR  NS r"   )rc   r1   isdirrd   )rQ   pr=   s     r$   rS   z6ImportlibFinder.contribute_to_path.<locals>.<listcomp>   se       7==a!<)!<!<!<==Q++++  r#   	distutilsc              3     K   | ]B}j                                                             |                                          V  Cd S r5   )r*   lower
startswith)rQ   ext_lib_dirrE   s     r$   	<genexpr>z5ImportlibFinder.contribute_to_path.<locals>.<genexpr>   s_       2
 2
 M!!,,[->->-@-@AA2
 2
 2
 2
 2
 2
r#   )r*   _is_setuptools_namespacer   r6   r1   r(   anyr
   r[   r   r\   r+   r'   parent)r8   rE   r=   r1   distutils_specorigin_paths    ``   r$   rH   z"ImportlibFinder.contribute_to_path   s    = 	4#D$7$788 	#     DD
 Y+% 	#c 2
 2
 2
 2
+2
 2
 2
 /
 /
 	# '^55kBBN '."7 '"")  K.//0M?Dr#   NrI   rJ   )r   r   r   r   r[   r^   EXTENSION_SUFFIXESSOURCE_SUFFIXESre   rV   r.   rC   rH   r"   r#   r$   rN   rN   a   s         11 	VUi.A.TUUU
R
Ri.A.Q
R
R
R	S
V
V	0C0U
V
V
V	W     / / / /b# # # # # #r#   rN   c                  "    e Zd ZdZddZddZdS )ExplicitNamespacePackageFinderz-A finder for the explicit namespace packages.r:   r'   r;   r<   r=   r>   r?   r,   r2   r@   c                    |rd                     ||gz             }t          j        |          rC|t          j        v r5t          j        |         j        }t          |ddt          j        |          S d S )N. 	namespacer(   r*   r+   r)   r-   )	rd   r   is_namespacer6   modules__path__r&   r   r!   rB   s        r$   rC   z*ExplicitNamespacePackageFinder.find_module   s      	6hhyG9455GW%% 	'S[*@ 	 [1:N",+9    tr#   rE   r&   c                    |j         S r5   r-   rG   s      r$   rH   z1ExplicitNamespacePackageFinder.contribute_to_path   s     ..r#   NrI   rJ   r   r   r   r   rC   rH   r"   r#   r$   r   r      sB        77   (/ / / / / /r#   r   c                  ,     e Zd ZdZd fdZddZ xZS )	ZipFinderz8Finder that knows how to find a module inside zip files.r1   r<   r2   r3   c                    t                                          |           |D ]H}|t          j        vr8	 t	          j        |          t          j        |<   3# t          j        $ r Y Dw xY wId S r5   )superr9   r6   path_importer_cache	zipimportzipimporterZipImportError)r8   r1   
entry_path	__class__s      r$   r9   zZipFinder.__init__   s     	 	J!88 :C:O"; ;C+J77 !/   H	 	s   !AA*)A*r:   r'   r;   r=   r>   r?   r,   r@   c                v    	 t          |          \  }}}n# t          $ r Y d S w xY wt          ||d||          S )Neggr   )_search_zipImportErrorr&   )r8   r:   r;   r=   r?   	file_typerX   r1   s           r$   rC   zZipFinder.find_module   sg    	(3L(A(A%Ix 	 	 	44	 '+
 
 
 	
s    
$$)r1   r<   r2   r3   rI   )r   r   r   r   r9   rC   __classcell__)r   s   @r$   r   r      sW        BB
 
 
 
 
 

 
 
 
 
 
 
 
r#   r   c                  "    e Zd ZdZddZddZdS )PathSpecFinderz/Finder based on importlib.machinery.PathFinder.r:   r'   r;   r<   r=   r>   r?   r,   r2   r@   c           	        t           j        j                            ||          }|V|j        d u }|s|j        nd }|rt
          j        nd }t          |j        ||j        |t          |j
        pg                     S |S )N)r1   r   )r[   r^   
PathFinderr\   r+   r   r!   r&   r(   rY   r-   )	r8   r:   r;   r=   r?   rE   is_namespace_pkgr*   module_types	            r$   rC   zPathSpecFinder.find_module  s     "-77n7UU 
	#{d2*:Dt{{H5EO*114KY!{ +/0O0USU+V+V    r#   rE   r&   c                >    |j         t          j        k    r|j        S d S r5   )r)   r   r!   r-   rG   s      r$   rH   z!PathSpecFinder.contribute_to_path  s$     9
// 	322tr#   NrI   rJ   r   r"   r#   r$   r   r     sB        99   *     r#   r   r*   pathlib.Pathr2   boolc                    	 t          | dz  d          5 }|                    d          }d d d            n# 1 swxY w Y   n# t          $ r Y dS w xY wd|v od|v }d|v od|v }|p|S )	Nz__init__.pyrbi   Fs   pkgutils   extend_paths   pkg_resourcess   declare_namespace(__name__))openreadOSError)r*   streamdataextend_pathdeclare_namespaces        r$   rx   rx   *  s    (]*D11 	%V;;t$$D	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%   uu$?4)?KD K%Ct%K  +++s,   A 7A ;A ;A 
AA+Iterator[tuple[str, zipimport.zipimporter]]c               #     K   t           j                                        D ]%\  } }t          |t          j                  r| |fV  &d S r5   )r6   r   items
isinstancer   r   )filepathimporters     r$   _get_zipimportersr   7  sZ      !5;;== % %(h	 566 	%H$$$$% %r#   modpathr<   1tuple[Literal[ModuleType.PY_ZIPMODULE], str, str]c           	     |   t                      D ]\  }}t          r|                    | d                   }n|                    | d                   }|rAt          rk|                    t          j        j                            |                     s3t          dd                    | dd                    d|d|           nj|                    t          j        j                            |                     s3t          dd                    | dd                    d|d|           t          j
        t          j                            |          t          j        j        z   t          j        j                            |           z   |fc S t          dd                    |                      )Nr   No module named r   r   z in /)r   r	   r\   rC   rc   r1   seprd   r   r   r    abspath)r   r   r   founds       r$   r   r   >  s    011  ( 	5!++GAJ77EE((44E 	 
))"'+*:*:7*C*CDD %+88GABBK0000(((GGE  
 ))"'+*:*:7*C*CDD !kxx,,,,hhhA  
 '))BGK7"'+:J:J7:S:SS   	" <'):):<<
=
==r#   search_pathr:   r'   r;   r>   r=   r?   r,   tuple[Finder, ModuleSpec]c                    t           D ]-} ||           }|                    ||||          }|(||fc S t          dd                    |                     )Nr   r   )_SPEC_FINDERSrC   r   rd   )r   r:   r;   r=   r?   finderfinder_instancerE   s           r$   _find_spec_with_pathr   Z  s       % % &--**\9n
 
  	$$$$
A,)?)?AA
B
BBr#   r1   c                d   |pt           j        }| dd         } d}| dd         }g }| r|                     d          }t          |||||p|          \  }}|                    |           | r|                    ||          }|j        t          j        k    r|	                    |          }| |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   r   )
r6   r1   popr   appendrH   r)   r   r   _replace)	r   r1   r7   r?   r;   r=   r:   r   rE   s	            r$   r\   r\   m  s    " CHE aaajGN111:LI
 
L++a..+7L)^5Kt
 
 	!!! 	H#66tYGGN9
00 	L==N=KKD  
L Kr#   )r*   r   r2   r   )r2   r   )r   r<   r2   r   )r   r<   r:   r'   r;   r>   r=   r>   r?   r,   r2   r   r5   )r   r>   r1   r,   r2   r&   ))
__future__r   rK   r   r[   importlib.machineryimportlib.utilrc   pathlibr6   r   collections.abcr   r   r   typingr   r   astroid.constr	   astroid.modutilsr
   r   r   version_infor   typing_extensionsEnumr   r&   r0   rN   r   r   r   r   rx   r   r   r   r\   r"   r#   r$   <module>r      s  
 # " " " " " 



              				  



     . . . . . . . .       " " " " " " " " $ $ $ $ $ $ ) ) ) ) ) )      v *))))))       < < < < < < < <"F "F "F "F "F "F "F "FJ] ] ] ] ]f ] ] ]@/ / / / /_ / / /:!
 !
 !
 !
 !
 !
 !
 !
H    V   B "	
, 
, 
, 
,% % % %> > > >8C C C C&& & & & & & &r#   