bg[ UdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZmZmZddlmZmZddlmZddlmZddlmZmZmZdd lmZmZerdd l m Z ndd l!m Z ej"e#Z$e j%&d rd Z'd Z(ndZ'dZ(e j)de j)dhZ*e j+dkre*,e j-.e j/d e*,e j-.e j0dnK#e1$rC e*,e j-.e j2dn #e1$rYnwxYwYnwxYwere j3dkre*,e4ee j)dj5dz e*,e4ee j)dj5dz e*,e4ee j)dj5dz e*,e4ee j)dj5dz e j+dkrk e j0Z/de6d<n#e1$r e j/Z/YnwxYwdgdZ7e*,e7de j8dkre*,e7de j)d e j)d!hZ9e:;e j<d"Z=Gd#d$e>Z?dgd%Z@efdhd)ZAdid0ZBedgd1ZCdgd2ZDdjd5ZEdkd7ZFdld9ZGdmd;ZHdnd>ZI dodpdBZJdqdrdCZK dodsdGZL dodtdIZMdqdudJZN dvdwdNZOdvdxdPZPdydQZQdzdSZRd{dUZSdqd|dXZTd}dZZU dod~d\ZVdd]ZWdd_ZXddaZYddbZZddfZ[dS)aVPython 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)CallableIterableSequence)redirect_stderrredirect_stdout) lru_cache)Path) IS_JYTHONIS_PYPY PY310_PLUS)specutil)stdlib_module_nameswin)pypyw)dllpyd)r)sostdlib platstdlibntdlls)lib_pypyz lib-python/3posixstrprefixpathreturnc|dtjddz}tjt ||S)Nz python%d.%d)sys version_infoosr!joinr )r! base_pythons a/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/astroid/modutils.py _posix_pathr+cs0#c&6rr&:: w||FD+666libllib64purelibplatlibTceZdZdZdS) NoSourceFilezbException raised when we are not able to get a python source file for a precompiled file. N)__name__ __module__ __qualname____doc__r,r*r2r2vsr,r2cztjtj|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!normcaserealpathr!s r*_normalize_pathr<|s* 7  BG,,T22 3 33r,filename is_jythonboolcN|s|S|d\}}}|r|dzS|S)Nz $py.class.py) partition)r=r>head has_pyclass_s r*_path_from_filenamerFs@ #--k::D+qe| Or, blacklist Sequence[str]dirnames list[str] filenamesNonecv|D]5}||vr||||vr||6dS)zaRemove files/directories in the black list. dirnames/filenames are usually from os.walk N)remove)rGrIrKnorecurss r*_handle_blacklistrPs]'' x   OOH % % % %  " "   X & & & ''r,c t|SN)r<r;s r*_cache_normalize_path_rSs 4  r,cB|st|St|S)zNormalize path with caching.)r<rSr;s r*_cache_normalize_pathrUs( %t$$$ !$ ' ''r, dotted_nametypes.ModuleTypec tj|S#t$rYnwxYwtt j5}t t j5}tj|}dddn #1swxYwYdddn #1swxYwY| }|rt d||| }|rt 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%modulesKeyErrorrioStringIOr importlib import_modulegetvalueloggererrorinfo)rVstderrstdoutmodule stderr_value stdout_values r*load_module_from_namerhs {;''       ' '66? 446 (55666666666666666666666666666666 ??$$L  5{L   ??$$L  5{L    MsB !!!B%B: BB B B BB!$B!partscFtd|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 .)rhr()ris r*load_module_from_modpathrls !% 1 11r,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_filerl)rmmodpaths r*load_module_from_filerqs ))G #G , ,,r,mod_pathcg}|D]r}||tj||}t |s,t jd|}|sdSsdS)z3Check there are some __init__.py all along the way.rkFT)appendr'r!r( _has_initr is_namespace)r!rrrppart old_namespaces r*check_modpath_has_initrys|Gtw||D$''  -chhw.?.?@@M  uu 4r, path_to_checklist[str] | Nonecbd}tj|}tj|}tj||r|}tj|}tj||r|}|retj|d}|t|d}d|tj DSdS)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 Nrcg|]}||Sr7r7).0pkgs r* z+_get_relative_base_path..sGGG3GGGGr,) r'r!r9abspath startswithr:splitextlensplitsep)r=rzimportable_path abs_filename real_filename base_pathrelative_base_paths r*_get_relative_base_pathrs OG$$]33M7??8,,L w %%00??'&G$$X..M w &&11-@@(' HG$$_55a8 &s='9'9';';<GG177??GGGG 4r,Sequence[str] | None is_package_cb'Callable[[str, list[str]], bool] | Nonectjt|}tj}|r||z }t j|tt|D]4}|st||}|s|J|||ddr|cS5td |d tj)Nz"Unable to find module for {} in {}z, )r'r! expanduserrFr%copy itertoolschainmaprUr ImportErrorformatr()r=r!rpaths_to_checkpathnamerps r*modpath_from_file_with_callbackr s w!!"5h"?"?@@HX]]__N $O1>BB    )(H==  ((( =73B3< 0 0 NNN  ,33Hfkk#(>S>STT  r,c.t||tS)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 )rry)r=r!s r*roro:s$ +8T;Q R RRr,rp context_file str | Nonec.t|||jSrR)file_info_from_modpathlocation)rpr!rs r*file_from_modpathrOs "'4 > > GGr,spec.ModuleSpecc|| tj|}n|}|ddkr? tdg|ddz||S#t$rt|||cYSwxYw|ddgkr5t jdtjjt jj St|||S) axGiven 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' Nrxml_xmlplusr'r!os.path)namertype) r'r!dirname_spec_from_modpathrr ModuleSpec__file__ ModuleType PY_SOURCE)rpr!rcontexts r*rrWs> gool;;qzU >%zlWQRR[&@$PP P > > >%gtW== = = = > T6N " "W%*    gtW 5 55sAA-,A-c |drdS|d}|9|dtvr*t|dkrt ||dSd}d}|ddkr| Jdg}d}|t|kr[||dkrO|dz }| Jdt j|}|t|kr ||dkOt|t|D]t} t|||dz|| !#t$rG|tdt|dz krd |d|cYcSwxYw|S) aGiven 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) rrkNrr$z.explicit relative import, but no context_file?r)r!r) rrBUILTIN_MODULESrrr'r!rrangermaxr()rVrrir!startiis r*get_module_partrs.i((y   c " "E 8 & &5zzA~~!+...8O!D F Qx2~~  $ $ ; % $ $ 3u::  %-2"5"5!   $ $ ; % $ $w|44 3u::  %-2"5"5 63u:: & &'' ' fq1un%D|      ' ' '3q#e**q.))))88E"1"I&& & & & & & ' sD44A FFF src_directorylist_allcg}tj|D]s\}}}||vr t||||s d|vrd|dd<*|D]F}t|r5tj||}||Gt|S)aGiven 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__.pyr7N)r'walkrP_is_python_filer!r(rt) rrGrfiles directoryrIrKr=srcs r*get_module_filesrs&E*,'-*@*@ " "& 8Y  ! ! )Xy999 M::HQQQK ! " "Hx(( "gll9h77 S!!! " Lr,include_no_extcntjt|}tj|\}}t D],}|d|}tj|r|cS-|r#|s!tj|r|St|)asGiven 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 rk)r'r!rrFrPY_SOURCE_EXTSexistsr2)r=rbaseorig_extext source_paths r*get_source_filersw28<<==HW%%h//ND(oooo 7>>+ & &     h27>>$+?+? x  r,cr|sdStj|dddtvS)z5Return: True if the filename is a python source file.FrN)r'r!rrr=s r*is_python_sourcers8 u 7  H % %a ( , >>r,modnamecF|ddtvS)z6Return: True if the modname is in the standard libraryrkr)rr)rs r*is_stdlib_modulers ==  a $7 77r,str | Iterable[str]cJ|dd} t|gn#t$rYdSwxYwdStt |t r"t|Stfd|DS)a Try to determine if a module is imported from one of the specified paths :param modname: name of the module :param path: paths to consider :return: true if the module: - is located on the path listed in one of the directory in `paths` rkrFNc3\K|]&}t|V'dSrRrrU)r~entryr=s r* z!module_in_path..(s:SSUx""#8#?#?@@SSSSSSr,) rrrr< isinstancerrrUany)rr!r=s @r*module_in_pathr smmC  #G$gY// uuux((H$@""#8#>#>??? SSSSdSSS S SSs / ==std_pathIterable[str] | Nonectjdtd|dd} t |gn#t $rYdSwxYwt j| SttD]'} t|rdS(|t}tfd|DS) 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 zWis_standard_module() is deprecated. Use, is_stdlib_module() or module_in_path() insteadr$) stacklevelrkrFNc3\K|]&}t|V'dSrRr)r~r!r=s r*rz%is_standard_module..Qs:UUDx""#8#>#>??UUUUUUr,)warningswarnDeprecationWarningrrrrrvr< EXT_LIB_DIRSrrU STD_LIB_DIRSr)rrr!r=s @r*is_standard_moduler+s  Ma mmC  #G$gY// uu $W----x((H   4T:: ; ; 55  UUUUHUUU U UUsA AA from_filec:tj|stj|}|tjvrdSt t jj | ddd|gS)a6Return 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` Frkr)maxsplitr) r'r!isdirrr%r?r] machinery PathFinder find_specr)rrs r* is_relativerTs 7== # #/GOOI.. CHu &00 MM#M * *1 - {    r,rc|sJd}|K tj||g}|j}nA#t$rtj||}|j}YnwxYwtj||}|jtjjkrj |jJt|j}||tjj S#t$r||cYSwxYw|jtjj kr|dS|jtjj krC|jJt|j}||tjj 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)rr)r)rrrrrr PY_COMPILEDr_replacerr2 C_BUILTIN PKG_DIRECTORYru)rpr!rr found_specs r*rrns NN7H +';;J!*HH + + +66J!*HHH +^GT22 $/555 :&222&z':;;H&&!(A'  : : :&&&99 9 9 9 : DO5 5 5""D"111 DO9 9 9"...Z011""H4?;T"UUU s"(&AAAC C*)C*c,|dS)zlReturn true if the given filename should be considered as a python file. .pyc and .pyo are ignored )rAz.soz.pydz.pyw)endswithrs r*rrs   ; < <>++c1 2 2 +$s* * * * + 4r,specobjc6|jtjjkSrR)rrr PY_NAMESPACErs r*rvrvs <4?7 77r,c6|jtjjkSrR)rrrrrs r* is_directoryrs <4?8 88r, module_namepackage_whitelistset[str]c |dtfdtdtdzDS)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 rkc3VK|]#}dd|vV$dS)rkN)r()r~xrris r*rzEis_module_name_part_of_extension_package_whitelist..sN56rr00r,r)rrrr)rrris `@r*2is_module_name_part_of_extension_package_whitelistrsk   c " "E :?3u::PQ>:R:R  r,)r!rr"r)r=rr>r?r"r)rGrHrIrJrKrJr"rL)rVrr"rW)rirHr"rW)rmrr"rW)r!rrrrJr"r?)r=rrzrr"r{)NN)r=rr!rrrr"rJrR)r=rr!rr"rJ)rprJr!rrrr"r)rprJr!rrrr"r)rVrrrr"r)F)rrrGrHrr?r"rJ)r=rrr?r"r)r=rr"r?)rrr"r?)rrr!rr"r?)rrrrr"r?)rrrrr"r?)rprJr!rrrr"r)r=rr"r?)rrr"r)rrr"r?)rrrrr"r?)\r6 __future__rr]importlib.machineryimportlib.utilr[rloggingr'r% sysconfigtypesrcollections.abcrrr contextlibrr functoolsr pathlibr astroid.constr r r astroid.interpreter._importrrrastroid._backport_stdlib_names getLoggerr3r`platformrrPY_COMPILED_EXTSget_pathrraddr!r(r real_prefixAttributeErrorbase_exec_prefixr&rparent__annotations__r+maxsizerdictfromkeysbuiltin_module_namesr Exceptionr2r<rFrPrSrUrhrlrqryrrrorrrrrrrrrrrrrurvrrr7r,r*r$s   #"""""   888888888877777777888888888822222222 C'''''''BBBBBB  8 $ $<5!!"N%N # "8,,.@i.@.N.NO 7d??RW\\#*f55666  cov>>????     RW\\#*>GG H H H H    D   s&((SS0i0::;;BZOPPQQQSS0i0::;;B^STTUUUSS0i0>>??FSTTUUU DD##L11 2 2 9N JKK7g o%%%%% 7777[[''((( {U W--..." "9--/Ay/A)/L/LM -- 8$??9 4444:C ' ' ' ' !!! !((((""""J 2 2 2 2 - - - -    """"N"&=A4SSSSS."&#HHHHH"&#0606060606f:::::|DI     F!!!!!.????8888 TTTT<&V&V&V&V&VR8"&&&&&&R====88889999      sH3D;;F3E54F5E=:F<E==FF J J/.J/