
    e@                    >   U 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Zd dlZd dlmZmZ d dlmZ d dlmZmZmZmZ d dlmZ d dlmZ dd	lmZ  G d
 de      Z G d dej:                        Zej>                  ej@                  ej>                  dZ!de"d<   ddhZ#de"d<    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*d&d!Z+d'd"Z,	 	 	 	 d(d#Z-	 	 	 	 	 	 	 	 	 	 	 	 d)d$Z.d*d+d%Z/y),    )annotationsN)IteratorSequence)Path)AnyLiteral
NamedTupleProtocol)
PY310_PLUS)EXT_LIB_DIRS   )utilc                  &    e Zd Z	 d	 	 	 	 	 	 	 ddZy)_MetaPathFinderc                     y N )selffullnamepathtargets       B/usr/lib/python3/dist-packages/astroid/interpreter/_import/spec.py	find_specz_MetaPathFinder.find_spec   s     	    N).)r   strr   Sequence[str] | Noner   ztypes.ModuleType | Nonereturnz%importlib.machinery.ModuleSpec | None)__name__
__module____qualname__r   r   r   r   r   r      s2    
 +.	 # (	
 
/r   r   c                  d   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y)
ModuleTypez(Python module types used for ModuleSpec.N)r   r   r    __doc__enumauto	C_BUILTINC_EXTENSIONPKG_DIRECTORYPY_CODERESOURCEPY_COMPILED	PY_FROZENPY_RESOURCE	PY_SOURCEPY_ZIPMODULEPY_NAMESPACEr   r   r   r"   r"   (   s    2		I$))+KDIIKMdiikO$))+K		I$))+K		I499;L499;Lr   r"   )_EditableFinder_EditableNamespaceFinder_SixMetaPathImporterzdict[str, ModuleType]_MetaPathFinderModuleTypesr0   r1   zset[str]_EditableFinderClassesc                  P    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<   y)
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.
    r   namezModuleType | NonetypeNz
str | Nonelocationoriginr   submodule_search_locations)r   r   r    r#   __annotations__r9   r:   r;   r   r   r   r6   r6   E   s4     I
HjFJ7; 4;r   r6   c                  h    e Zd ZdZdddZej                  	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 	 d	dZy)
Finderz@A finder is a class which knows how to find a particular module.Nc                6    |xs t         j                  | _        y r   )sysr   _path)r   r   s     r   __init__zFinder.__init__V   s    %SXX
r   c                     y)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   r   modnamemodule_parts	processedsubmodule_paths        r   find_modulezFinder.find_moduleY       r   c                     y)z7Get a list of extra paths where this finder can search.Nr   r   specrG   s      r   contribute_to_pathzFinder.contribute_to_pathr   rJ   r   r   )r   r   r   None
rE   r   rF   Sequence[str]rG   	list[str]rH   r   r   zModuleSpec | NonerM   r6   rG   rR   r   r   )	r   r   r    r#   rB   abcabstractmethodrI   rN   r   r   r   r>   r>   S   su    J& 	 $ 	
 - 
 0FF+4F	Fr   r>   c                     e Zd ZU dZej
                  j                  D  cg c]  }|t        j                  f c}}} ej
                  j                  D  cg c]  }|t        j                  f c}}} z   ej
                  j                  D  cg c]  }|t        j                  f c}}} z   Zded<   	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZyc c}}} w c c}}} w c c}}} w )	ImportlibFinderz'A finder based on the importlib module.z Sequence[tuple[str, ModuleType]]	_SUFFIXESc                x   |t        |      }n|t        j                  v rt        |d t        j
                        S 	 t        j                         5  t        j                  dt               t        j                  j                  |      }d d d        rW|j                  t        j                  j                  u r1t        |t!        |j"                  dd       t        j$                        S t        j(                  }|D ]  }t*        j(                  j-                  ||      }ddt        j                  j.                  d   fD ]f  }d|z   }	t*        j(                  j-                  ||	      }
t*        j(                  j1                  |
      sHt        ||t        j2                        c c S  t4        j6                  D ][  \  }}||z   }t*        j(                  j-                  ||      }
t*        j(                  j1                  |
      sKt        ||
|      c c S   y # 1 sw Y   xY w# t&        $ r Y Jw xY w)	N)r7   r9   r8   ignore)categoryfilenamez.pyz.pyir   rB   )listr@   builtin_module_namesr6   r"   r&   warningscatch_warningsfilterwarningsUserWarning	importlibr   r   loader	machineryFrozenImportergetattrloader_stater+   
ValueErrorr   osjoinBYTECODE_SUFFIXESisfiler(   rW   rX   )r   rE   rF   rG   rH   rM   entrypackage_directorysuffixpackage_file_name	file_pathtype_	file_names                r   rI   zImportlibFinder.find_module   s    %!.1N000)) ,,. =++H{K$>>33G<D=  **99: &$!():):J!M'11  !XXN# 	TE "UG < &)*=*=*O*OPQ*RS $.$7!GGLL):<MN	77>>),%$!2'55 	 "1!:!: T#f,	GGLL	:	77>>),%7YUSS	T	T  E= =  s*   H, ;HA H, H)$H, ,	H98H9c           	        j                   y t        t        j                               rzt        j                  D cg c]_  }t
        j                  j                  t        j                  j                  |g|       r t        j                  j                  |g| a }}|S j                  dk(  rt        fdt        D              sit        j                  j                  d      }|r9|j                  r-t        |j                        }t        |j                         g}|S j                   g}|S j                   g}|S c c}w )N	distutilsc              3     K   | ];  }j                   j                         j                  |j                                = y wr   )r9   lower
startswith).0ext_lib_dirrM   s     r   	<genexpr>z5ImportlibFinder.contribute_to_path.<locals>.<genexpr>   s:      2
 MM!,,[->->-@A2
s   AA)r9   _is_setuptools_namespacer   r@   r   rj   isdirrk   r7   anyr   rc   r   r   r:   r   parent)r   rM   rG   pr   distutils_specorigin_paths    `     r   rN   z"ImportlibFinder.contribute_to_path   s    == #D$78
 77==a!<)!<= Q++D 2 ) YY+%c 2
+2
 /
 '^^55kBN."7"7"")) K../0
    MM?D3s   A$ENrP   rS   )r   r   r    r#   rc   re   EXTENSION_SUFFIXESr"   r'   SOURCE_SUFFIXESr-   rl   r*   rX   r<   rI   rN   )rz   sr"   s   000r   rW   rW   x   s    1 /8.A.A.T.TUU!Z##	$U.7.A.A.Q.Q
R
RAz##$
R	S090C0C0U0U
V
V1Az%%&
V	W / 33 $3 	3
 -3 
3j##+4#	#u 	V
R
Vs   CC
C
rW   c                  @    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZy)ExplicitNamespacePackageFinderz-A finder for the explicit namespace packages.c                    |rdj                  g ||      }t        j                  |      rM|t        j                  v r;t        j                  |   j
                  }t        |ddt        j                  |      S y )N. 	namespacer7   r9   r:   r8   r;   )	rk   r   is_namespacer@   modules__path__r6   r"   r/   rD   s        r   rI   z*ExplicitNamespacePackageFinder.find_module   st     hh44G45GW%'S[[*@ [[1::N",,+9  r   c                    |j                   S r   r;   rL   s      r   rN   z1ExplicitNamespacePackageFinder.contribute_to_path   s     ...r   NrP   rS   r   r   r    r#   rI   rN   r   r   r   r   r      sW    7 $ 	
 - 
(//+4/	/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.c                    t         |   |       |D ]<  }|t        j                  vs	 t	        j
                  |      t        j                  |<   > y # t        j                  $ r Y Uw xY wr   )superrB   r@   path_importer_cache	zipimportzipimporterZipImportError)r   r   
entry_path	__class__s      r   rB   zZipFinder.__init__   sj     	J!8!88:C:O:O";C++J7	 !// s   &AA)(A)c                `    	 t        |      \  }}}t        ||d||      S # t        $ r Y y w xY w)Neggr   )_search_zipImportErrorr6   )r   rE   rF   rG   rH   	file_typer\   r   s           r   rI   zZipFinder.find_module  sJ    	(3L(A%Ix '+
 	
  		s   ! 	--)r   rQ   r   rO   rP   )r   r   r    r#   rB   rI   __classcell__)r   s   @r   r   r      s@    B	

 $
 	

 -
 

r   r   c                  @    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZy)PathSpecFinderz/Finder based on importlib.machinery.PathFinder.c           
     :   t         j                  j                  j                  ||      }|m|j                  d u }|s|j                  nd }|rt
        j                  nd }t        |j                  ||j                  |t        |j                  xs g             S |S )N)r   r   )rc   re   
PathFinderr   r:   r"   r/   r6   r7   r]   r;   )	r   rE   rF   rG   rH   rM   is_namespace_pkgr9   module_types	            r   rI   zPathSpecFinder.find_module  s     ""--77n7U#{{d2*:t{{H5E*114KYY!{{ +/0O0O0USU+V  r   c                V    |j                   t        j                  k(  r|j                  S y r   )r8   r"   r/   r;   rL   s      r   rN   z!PathSpecFinder.contribute_to_path4  s%     99
///222r   NrP   rS   r   r   r   r   r   r     sW    9 $ 	
 - 
*+4	r   r   c                    	 t        | dz  d      5 }|j                  d      }d d d        dv xr d|v }d|v xr d|v }|xs |S # 1 sw Y   #xY w# t        $ r Y yw xY w)	Nz__init__.pyrbi   Fs   pkgutils   extend_paths   pkg_resourcess   declare_namespace(__name__))openreadOSError)r9   streamdataextend_pathdeclare_namespaces        r   r}   r}   D  s    (]*D1 	%V;;t$D	% $?4)?KD K%Ct%K  +++	% 	% s'   A AA A
A 	AAc               #     K   t         j                  j                         D ]&  \  } }t        |t        j
                        s!| |f ( y wr   )r@   r   items
isinstancer   r   )filepathimporters     r   _get_zipimportersr   Q  sD     !55;;= %(h	 5 56H$$%s   ?A	Ac           	     6   t               D ]o  \  }}t        r|j                  | d         }n|j                  | d         }|s9t        r^|j                  t        j
                  j                  j                  |             st        ddj                  | dd        d|d|       |j                  t        j
                  j                  j                  |             s&t        ddj                  | dd        d|d|       t        j                  t        j
                  j                  |      t        j
                  j                  z   t        j
                  j                  j                  |       z   |fc S  t        ddj                  |              )Nr   No module named r   r   z in /)r   r   r   rI   rj   r   seprk   r   r"   r.   abspath)modpathr   r   founds       r   r   r   W  sN    01 (!++GAJ7E((4E))"''++*:*:7*CD%88GABK0(GE  ))"''++*:*:7*CD!xx,hA 
 '')BGGKK7"''++:J:J7:SS #, ('):(;<
==r   c           	        t         D ]&  } ||       }|j                  ||||      }|"||fc S  t        j                  D ]  }|j                  j
                  }	|	t        vr	 |j
                  }	|	t        vr7t        |	   }
t        |d      sM|j                  ||      }|sb|t        |j                  |
|j                  |j                  |j                        fc S  t        ddj                  |             # t        $ r Y w xY w)Nr   r   r   )_SPEC_FINDERSrI   r@   	meta_pathr   r   r3   AttributeErrorhasattrr   r6   r7   r:   r;   r   rk   )search_pathrE   rF   rG   rH   finderfinder_instancerM   meta_findermeta_finder_namer   s              r   _find_spec_with_pathr   s  s3      % -**\9n
 <$$% }} "&0099#==#.#7#7   'AA01AB {K0$$Wn=IIKKKK33	 	3"H (,)?(@A
BB7 " s   "C;;	DDc                   |xs t         j                  }| dd } d}| dd }g }| r| j                  d      }t        |||||xs |      \  }}|j	                  |       | rAt        |t              r|j                  ||      }n|j                  t        v r|j                  }|j                  t        j                  k(  r|j                  |      }| 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   )r@   r   popr   appendr   r>   rN   r   r4   r;   r8   r"   r(   _replace)	r   r   rA   rH   rF   rG   rE   r   rM   s	            r   r   r     s    " CHHE ajGN1:LI
++a.+7L)^5Kt
 	!&&)!'!:!:4!K $::!%!@!@99
000==N=KD! $ Kr   )r9   zpathlib.Pathr   bool)r   z+Iterator[tuple[str, zipimport.zipimporter]])r   rQ   r   z1tuple[Literal[ModuleType.PY_ZIPMODULE], str, str])r   rQ   rE   r   rF   rR   rG   rR   rH   r   r   z+tuple[Finder | _MetaPathFinder, ModuleSpec]r   )r   rR   r   r   r   r6   )0
__future__r   rT   r$   rc   importlib.machineryimportlib.utilrj   pathlibr@   typesr_   r   collections.abcr   r   r   typingr   r   r	   r
   astroid.constr   astroid.modutilsr   r   r   r   Enumr"   r-   r/   r3   r<   r4   r6   r>   rW   r   r   r   r   r}   r   r   r   r   r   r   r   <module>r      sl  
 # 
     	  
    .  5 5 $ ) 
h  " "++ * 7 7&005 1  $  < <"F "FJaf aH/_ /: 
  
FV B "	
,%>>6>85C5C5C 5C 	5C
 )5C 15Cp,r   