
    cBV              	      ~   U d Z 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mZmZmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZ dd	lmZmZ  ej        e          Z e
j!        "                    d
          rdZ#dZ$ndZ#dZ$ ej%        d           ej%        d          hZ&e	j'        dk    re&(                    e	j)        *                    e
j+        d                     	 e&(                    e	j)        *                    e
j,        d                     nK# e-$ rC 	 e&(                    e	j)        *                    e
j.        d                     n# e-$ r Y nw xY wY nw xY were
j/        dk     re&(                     e0 e ej%        d                    j1        dz                       e&(                     e0 e ej%        d                    j1        dz                       e&(                     e0 e ej%        d                    j1        dz                       e&(                     e0 e ej%        d                    j1        dz                       e	j'        dk    rk	 e
j,        Z+de2d<   n# e-$ r
 e
j+        Z+Y nw xY wdcdZ3e&(                     e3d                     e
j4        dk    re&(                     e3d                      ej%        d           ej%        d           hZ5e67                    e
j8        d!          Z9 G d" d#e:          Z;dcd$Z<efddd(Z=ded/Z> e            dcd0            Z?dcd1Z@dfd4ZAdgd6ZBdhd8ZCdid:ZDdjd=ZE	 	 dkdldAZFdmdndBZG	 	 dkdodFZH	 	 dkdpdHZIdmdqdIZJ	 drdsdMZKdrdtdOZLdudPZMdmdvdTZNdwdVZO	 	 dkdxdXZPdydYZQdzd[ZRd{d]ZSd{d^ZTd|dbZUdS )}aV  Python modules manipulation utility functions.

:type PY_SOURCE_EXTS: tuple(str)
:var PY_SOURCE_EXTS: list of possible python source file extension

:type STD_LIB_DIRS: set of str
:var STD_LIB_DIRS: directories where standard modules are located

:type BUILTIN_MODULES: dict
:var BUILTIN_MODULES: dictionary with builtin module names has key
    )annotationsN)CallableIterableSequence)redirect_stderrredirect_stdout)	lru_cache)Path)	IS_JYTHONIS_PYPY)specutilwin)pypyw)dllpyd)r   )sostdlib
platstdlibntdlls)      lib_pypyzlib-python/3posixstrprefixpathreturnc                |    dt           j        d d         z  }t          j                            t
          | |          S )Nzpython%d.%d   )sysversion_infoosr   joinr   )r   base_pythons     0lib/python3.11/site-packages/astroid/modutils.py_posix_pathr)   ]   s0    #c&6rr&::w||FD+666    libl        lib64purelibplatlibTc                      e Zd ZdZdS )NoSourceFilezbException raised when we are not able to get a python
    source file for a precompiled file.
    N)__name__
__module____qualname____doc__ r*   r(   r0   r0   p   s           r*   r0   c                z    t           j                            t           j                            |                     S )zResolve symlinks in path and convert to absolute path.

    Note that environment variables and ~ in the path need to be expanded in
    advance.

    This can be cached by using _cache_normalize_path.
    )r%   r   normcaserealpathr   s    r(   _normalize_pathr:   v   s*     7BG,,T22333r*   filename	is_jythonboolc                N    |s| S |                      d          \  }}}|r|dz   S | S )Nz	$py.class.py)	partition)r;   r<   headhas_pyclass_s        r(   _path_from_filenamerD      s@     #--k::D+q e|Or*   	blacklistSequence[str]dirnames	list[str]	filenamesNonec                v    | D ]5}||v r|                     |           ||v r|                     |           6dS )zaRemove files/directories in the black list.

    dirnames/filenames are usually from os.walk
    N)remove)rE   rG   rI   norecurss       r(   _handle_blacklistrN      sa      ' 'x 	'OOH%%%%" 	'X&&&	' 'r*   c                     t          |           S N)r:   r9   s    r(   _cache_normalize_path_rQ      s    4   r*   c                B    | st          |           S t          |           S )zNormalize path with caching.)r:   rQ   r9   s    r(   _cache_normalize_pathrS      s(    
  %t$$$!$'''r*   dotted_nametypes.ModuleTypec                   	 t           j        |          S # t          $ r Y nw xY wt          t	          j                              5 }t          t	          j                              5 }t          j        |           }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |	                                }|rt                              d| |           |	                                }|rt                              d| |           |S )zLoad a Python module from its name.

    :type dotted_name: str
    :param dotted_name: python name of a module or package

    :raise ImportError: if the module or package is not found

    :rtype: module
    :return: the loaded module
    Nz&Captured stderr while importing %s:
%sz&Captured stdout while importing %s:
%s)r#   modulesKeyErrorr   ioStringIOr   	importlibimport_modulegetvalueloggererrorinfo)rT   stderrstdoutmodulestderr_valuestdout_values         r(   load_module_from_namerf      s   {;''   
 
	'	' 66?
4 4 6	(556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
 ??$$L 
5{L	
 	
 	
 ??$$L 
5{L	
 	
 	
 MsB    
!!!B%B:BB
	
BB
	BB!$B!partsc                F    t          d                    |                     S )zLoad a python module from its split name.

    :param parts:
      python name of a module or package split on '.'

    :raise ImportError: if the module or package is not found

    :return: the loaded module
    .)rf   r&   )rg   s    r(   load_module_from_modpathrj      s     !%111r*   filepathc                >    t          |           }t          |          S )zLoad a Python module from it's path.

    :type filepath: str
    :param filepath: path to the python module or package

    :raise ImportError: if the module or package is not found

    :rtype: module
    :return: the loaded module
    )modpath_from_filerj   )rk   modpaths     r(   load_module_from_filero      s      ))G#G,,,r*   mod_pathc                    g }|D ]r}|                     |           t          j                            | |          } t	          |           s,t          j        d                    |                    }|s dS sdS )z3Check there are some __init__.py all along the way.ri   FT)appendr%   r   r&   	_has_initr   is_namespace)r   rp   rn   partold_namespaces        r(   check_modpath_has_initrw      s|    G  tw||D$'' 	 -chhw.?.?@@M  uu4r*   path_to_checklist[str] | Nonec                b   d}t           j                            |          }t           j                            |           }t           j                            |                              |          r|}t           j                            |           }t           j                            |                              |          r|}|ret           j                            |          d         }|t          |          d         }d |                    t           j	                  D             S dS )a>  Extracts the relative mod path of the file to import from.

    Check if a file is within the passed in path and if so, returns the
    relative mod path from the one passed in.

    If the filename is no in path_to_check, returns None

    Note this function will look for both abs and realpath of the file,
    this allows to find the relative base path even if the file is a
    symlink of a file in the passed in path

    Examples:
        _get_relative_base_path("/a/b/c/d.py", "/a/b") ->  ["c","d"]
        _get_relative_base_path("/a/b/c/d.py", "/dev") ->  None
    Nr   c                    g | ]}||S r5   r5   ).0pkgs     r(   
<listcomp>z+_get_relative_base_path.<locals>.<listcomp>  s    GGG3GGGGr*   )
r%   r   r7   abspath
startswithr8   splitextlensplitsep)r;   rx   importable_pathabs_filenamereal_filename	base_pathrelative_base_paths          r(   _get_relative_base_pathr      s     OG$$]33M7??8,,L	w%%00?? '&G$$X..M	w&&11-@@ ('
  HG$$_55a8	&s='9'9';';<GG177??GGGG4r*   Sequence[str] | Noneis_package_cb'Callable[[str, list[str]], bool] | Nonec                   t           j                            t          |                     } t          j                                        }|r||z  }t          j        |t          t          |                    D ]4}|st          | |          }|s|J  |||d d                   r|c S 5t          d                    | d                    t          j                                      )Nz"Unable to find module for {} in {}z, 
)r%   r   
expanduserrD   r#   copy	itertoolschainmaprS   r   ImportErrorformatr&   )r;   r   r   paths_to_checkpathnamern   s         r(   modpath_from_file_with_callbackr     s    
 w!!"5h"?"?@@HX]]__N $O1>BB  
 
  	)(H== 	(((=73B3<00 	NNN	 ,33Hfkk#(>S>STT  r*   c                .    t          | |t                    S )a*  Get the corresponding split module's name from a filename.

    This function will return the name of a module or package split on `.`.

    :type filename: str
    :param filename: file's path for which we want the module's name

    :type Optional[List[str]] path:
      Optional list of path where the module or package should be
      searched (use sys.path if nothing or None is given)

    :raise ImportError:
      if the corresponding module's name has not been found

    :rtype: list(str)
    :return: the corresponding split module's name
    )r   rw   )r;   r   s     r(   rm   rm   4  s    $ +8T;QRRRr*   rn   context_file
str | Nonec                .    t          | ||          j        S rP   )file_info_from_modpathlocation)rn   r   r   s      r(   file_from_modpathr   I  s    
 "'4>>GGr*   spec.ModuleSpecc                |   | t           j                            |          }n|}| d         dk    r?	 t          dg| dd         z   ||          S # t          $ r t          | ||          cY S w xY w| ddgk    r5t          j        dt           j        j        t
          j        j	        	          S t          | ||          S )
ax  Given a mod path (i.e. split module / package name), return the
    corresponding file.

    Giving priority to source file over precompiled file if it exists.

    :param modpath:
      split module's name (i.e name of a module or package split
      on '.')
      (this means explicit relative imports that start with dots have
      empty strings in this list!)

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

    :param context_file:
      context file to consider, necessary if the identifier has been
      introduced using a relative import unresolvable in the actual
      context (i.e. modutils)

    :raise ImportError: if there is no such module in the directory

    :return:
      the path to the module's file or None if it's an integrated
      builtin module such as 'sys'
    Nr   xml_xmlplus   r%   r   os.path)namer   type)
r%   r   dirname_spec_from_modpathr   r   
ModuleSpec__file__
ModuleType	PY_SOURCE)rn   r   r   contexts       r(   r   r   Q  s    >   gool;;qzU 
	>%zlWQRR[&@$PPP 	> 	> 	>%gtW=====	>	T6N	" 
W%*
 
 
 	

 gtW555s   A A-,A-c           	        |                      d          rdS |                     d          }|9|d         t          v r*t          |          dk    rt	          |           |d         S d}d}|d         dk    r|
J d            g }d}||         dk    r<|dz  }|
J d            t
          j                            |          }||         dk    <t          |t          |                    D ]t}	 t          |||dz            ||	           !# t          $ rG |t          dt          |          dz
            k     r d                    |d|                   cY c S w xY w| S )
a  Given a dotted name return the module part of the name :

    >>> get_module_part('astroid.as_string.dump')
    'astroid.as_string'

    :param dotted_name: full name of the identifier we are interested in

    :param context_file:
      context file to consider, necessary if the identifier has been
      introduced using a relative import unresolvable in the actual
      context (i.e. modutils)

    :raise ImportError: if there is no such module in the directory

    :return:
      the module part of the name or None if we have not been able at
      all to import the given name

    XXX: deprecated, since it doesn't handle package precedence over module
    (see #10066)
    r   ri   Nr   r"    z.explicit relative import, but no context_file?r   )r   r   )r   r   BUILTIN_MODULESr   r   r%   r   r   ranger   maxr&   )rT   r   rg   r   startiis         r(   get_module_partr     s   . i(( yc""E  8& 	5zzA~ /!+...8O!DFQx2~ 	< 	<;	< 	< 	< 
-2
 5!	< 	<;	< 	< 	< w|44 -2
 5 63u::&& ' '	'fq1un%D|      	' 	' 	'3q#e**q.))) 88E"1"I&&&&&&&	' s   0DAEEFsrc_directorylist_allc                   g }t          j        |           D ]s\  }}}||v rt          |||           |sd|vrd|dd<   *|D ]F}t          |          r5t           j                            ||          }|                    |           Gt|S )a  Given a package directory return a list of all available python
    module's files in the package and its subpackages.

    :param src_directory:
      path of the directory corresponding to the package

    :param blacklist: iterable
      list of files or directories to ignore.

    :param list_all:
        get files from all paths, including ones without __init__.py

    :return:
      the list of all available python module's files in the package and
      its subpackages
    z__init__.pyr5   N)r%   walkrN   _is_python_filer   r&   rr   )	r   rE   r   files	directoryrG   rI   r;   srcs	            r(   get_module_filesr     s    & E*,'-*@*@ " "&	8Y	! 	)Xy999 	M: 	HQQQK! 	" 	"Hx(( "gll9h77S!!!	" Lr*   include_no_extc                n   t           j                            t          |                     } t           j                            |           \  }}t
          D ],}| d| }t           j                            |          r|c S -|r#|s!t           j                            |          r|S t          |           )as  Given a python module's file name return the matching source file
    name (the filename will be returned identically if it's already an.

    absolute path to a python source file...)

    :param filename: python module's file name

    :raise NoSourceFile: if no source file exists on the file system

    :return: the absolute path of the source file if it exists
    ri   )r%   r   r   rD   r   PY_SOURCE_EXTSexistsr0   )r;   r   baseorig_extextsource_paths         r(   get_source_filer     s     w28<<==HW%%h//ND(  oooo7>>+&& 		 h 27>>$+?+? 
x
 
  r*   c                r    | sdS t           j                            |           d         dd         t          v S )z5Return: True if the filename is a python source file.Fr   N)r%   r   r   r   r;   s    r(   is_python_sourcer     s8     u7H%%a(,>>r*   modnamestd_pathIterable[str] | Nonec                r   |                      d          d         } 	 t          | g          n# t          $ r Y dS w xY wt          j        |            S t                    t          D ]'}                    t          |                    r dS (|t          }t          fd|D                       S )a|  Try to guess if a module is a standard python module (by default,
    see `std_path` parameter's description).

    :param modname: name of the module we are interested in

    :param std_path: list of path considered has standard

    :return:
      true if the module:
      - is located on the path listed in one of the directory in `std_path`
      - is a built-in module
    ri   r   FNc              3  \   K   | ]&}                     t          |                    V  'd S rP   )r   rS   )r|   r   r;   s     r(   	<genexpr>z%is_standard_module.<locals>.<genexpr>!  s:      UUDx""#8#>#>??UUUUUUr*   )r   r   r   r   rt   r:   EXT_LIB_DIRSr   rS   STD_LIB_DIRSany)r   r   r   r;   s      @r(   is_standard_moduler     s     mmC  #G$gY//    uu  .$W----x((H  4T::;; 	55	  UUUUHUUUUUUs   / 
==	from_filec                :   t           j                            |          st           j                            |          }|t          j        v rdS t          t          j        j        	                    | 
                    dd          d         |g                    S )a6  Return true if the given module name is relative to the given
    file name.

    :param modname: name of the module we are interested in

    :param from_file:
      path of the module from which modname has been imported

    :return:
      true if the module has been imported relatively to `from_file`
    Fri   r   )maxsplitr   )r%   r   isdirr   r#   r=   r[   	machinery
PathFinder	find_specr   )r   r   s     r(   is_relativer   $  s     7==## /GOOI..	CH u&00MM#M**1-	{	
 	
  r*   r   c                   | sJ d}|K	 t          j        | |g          }|j        }nA# t          $ r t          j        | |          }|j        }Y nw xY wt          j        | |          }|j        t           j        j        k    rj	 |j        J t          |j                  }|                    |t           j        j	                  S # t          $ r |                    |          cY S w xY w|j        t           j        j        k    r|                    d          S |j        t           j        j        k    rC|j        J t          |j                  }|                    |t           j        j	                  S |S )zGiven a mod path (i.e. split module / package name), return the
    corresponding spec.

    this function is used internally, see `file_from_modpath`'s
    documentation for more information
    N)r   r   )r   )r   r   r   r   r   r   PY_COMPILEDr   _replacer   r0   	C_BUILTINPKG_DIRECTORYrs   )rn   r   r   r   
found_specs        r(   r   r   >  s    NNNH 3	+';;J!*HH 	+ 	+ 	+66J!*HHH	+ ^GT22
$/55 V	:&222&z':;;H&&!(A '     	: 	: 	:&&&99999	:	DO5	5 V""D"111	DO9	9 V"...Z011""H4?;T"UUUs"   ( &AAAC  C*)C*c                ,    |                      d          S )zlReturn true if the given filename should be considered as a python file.

    .pyc and .pyo are ignored
    )r?   z.soz.pydz.pyw)endswithr   s    r(   r   r   g  s    
 ;<<<r*   r   c                    t           j                            | d          }t          dz   D ]1}t           j                            |dz   |z             r
|dz   |z   c S 2dS )z]If the given directory has a valid __init__ file, return its path,
    else return None.
    __init__)pycpyori   N)r%   r   r&   r   r   )r   mod_or_packr   s      r(   rs   rs   o  sm     ',,y*55K. + +7>>++c122 	+$s****	+4r*   specobjc                6    | j         t          j        j        k    S rP   )r   r   r   PY_NAMESPACEr   s    r(   rt   rt   z  s    <4?777r*   c                6    | j         t          j        j        k    S rP   )r   r   r   r   r   s    r(   is_directoryr   ~  s    <4?888r*   module_namepackage_whitelistset[str]c           	         |                      d          t          fdt          dt                    dz             D                       S )z
    Returns True if one part of the module name is in the package whitelist.

    >>> is_module_name_part_of_extension_package_whitelist('numpy.core.umath', {'numpy'})
    True
    ri   c              3  V   K   | ]#}d                      d|                   v V  $dS )ri   N)r&   )r|   xr   rg   s     r(   r   zEis_module_name_part_of_extension_package_whitelist.<locals>.<genexpr>  sN        56rr00     r*   r   )r   r   r   r   )r   r   rg   s    `@r(   2is_module_name_part_of_extension_package_whitelistr     sk     c""E     :?3u::PQ>:R:R     r*   )r   r   r    r   )r;   r   r<   r=   r    r   )rE   rF   rG   rH   rI   rH   r    rJ   )rT   r   r    rU   )rg   rF   r    rU   )rk   r   r    rU   )r   r   rp   rH   r    r=   )r;   r   rx   r   r    ry   )NN)r;   r   r   r   r   r   r    rH   rP   )r;   r   r   r   r    rH   )rn   rH   r   r   r   r   r    r   )rn   rH   r   r   r   r   r    r   )rT   r   r   r   r    r   )F)r   r   rE   rF   r   r=   r    rH   )r;   r   r   r=   r    r   )r;   r   r    r=   )r   r   r   r   r    r=   )r   r   r   r   r    r=   )rn   rH   r   r   r   r   r    r   )r;   r   r    r=   )r   r   r    r   )r   r   r    r=   )r   r   r   r   r    r=   )Vr4   
__future__r   r[   importlib.machineryimportlib.utilrY   r   loggingr%   r#   	sysconfigtypescollections.abcr   r   r   
contextlibr   r   	functoolsr	   pathlibr
   astroid.constr   r   astroid.interpreter._importr   r   	getLoggerr1   r^   platformr   r   PY_COMPILED_EXTSget_pathr   r   addr   r&   r   real_prefixAttributeErrorbase_exec_prefixr$   r   parent__annotations__r)   maxsizer   dictfromkeysbuiltin_module_namesr   	Exceptionr0   r:   rD   rN   rQ   rS   rf   rj   ro   rw   r   r   rm   r   r   r   r   r   r   r   r   r   r   rs   rt   r   r   r5   r*   r(   <module>r     s&  

 
 
 # " " " " "             				      				 



      8 8 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 7             , , , , , , , , 2 2 2 2 2 2 2 2		8	$	$ <5!! "N%N
 #	"8,,.@i.@.N.NO7d? RW\\#*f55666
 	cov>>????   	RW\\#*>GGHHHH 	 	 	D	  s&(  SS0i0::;;BZOPPQQQSS0i0::;;B^STTUUU SS0i0>>??FSTTUUUDD##L11229NJKK   7g /
o%%%%%   7 7 7 7 [[''(((
{U / 	W--..."	"9--/Ay/A)/L/LM-- 8$??    9   4 4 4 4 :C     ' ' ' ' ! ! ! !( ( ( (" " " "J
2 
2 
2 
2- - - -
 
 
 
" " " "N "&=A    4S S S S S. "&#H H H H H "&#06 06 06 06 06f9 9 9 9 9z DI         F! ! ! ! !.? ? ? ? V  V  V  V  VF   8 "&& & & & &R= = = =   8 8 8 89 9 9 9     sH   23D& &E.,3E E. E(%E.'E((E.-E.>J JJ