bgdIvdZddlmZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z ddlmZddlmZmZmZmZmZmZdd lmZmZdd lmZmZmZdd lmZerdd lm Z nej!d Z dZ"dZ#dZ$d7dZ%d8dZ&Gddej'Z(d9d"Z) d:d;d(Z*dd?d1Z-d>d@d2Z. dAdBd6Z/dS)CzThe AstroidBuilder makes astroid from living object and / or from _ast. The builder is not thread safe and can't be used to parse different sources at the same time. ) annotationsN)IteratorSequence) TextIOWrapper)detect_encoding) TYPE_CHECKING)basesmodutilsnodes raw_building rebuilderutil) ParserModuleget_parser_module)AstroidBuildingErrorAstroidSyntaxErrorInferenceError)AstroidManager)objectsr__z#@zmisplaced type annotationfilenamestrreturntuple[TextIOWrapper, str, str]ct|d5}t|jd}dddn #1swxYwYt|d|}|}|||fS)Nrbr)newlineencoding)openrreadlineread)r byte_streamrstreamdatas `/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/astroid/builder.pyopen_source_filer&,s h  <";#788;<<<<<<<<<<<<<<< (D8 < < z#_can_assign_attr..;s%C%C%CTdj%C%C%CFzbuiltins.object)slotsNotImplementedErrorqname)r'r)r4s r%_can_assign_attrr75su   X%C%CU%C%C%CCC5      ::<<, ,,s ) 66cjeZdZdZ d"d#fd Z d$d%dZd$d&dZ d'd(dZd)dZd*dZ d+dZ d,d!Z xZ S)-AstroidBuilderaClass for building an astroid tree from source code or from a live module. The param *manager* specifies the manager class which should be used. If no manager is given, then the default one will be used. The param *apply_transforms* determines if the transforms should be applied after the tree was built from source or from a live object, by default being True. NTmanagerAstroidManager | Noneapply_transformsr+rNonecXt|||_dSN)super__init___apply_transforms)selfr:r< __class__s r%rAzAstroidBuilder.__init__Js+ !!!!1r3moduletypes.ModuleTypemodnamer* nodes.Modulec^d}t|dd}t|dd}|r8|p|j}||}|r||||}|u|stjtj|\}}|dvr;tj |dzr| |dz|}|9| |||}|j r|j |}t|t jsJ|S)z/Build an astroid from a living module instance.N__file__ __loader__)path>.pyc.pyo.pyrOrGrL)getattr__name__ get_source string_buildosrLsplitextr _path_from_filenameexists file_build inspect_buildrB_managervisit_transforms isinstancer Module) rCrErGr'rLloadersourcepath_exts r% module_buildzAstroidBuilder.module_buildPs@vz400t44  E0G&&w//F E((t(DD > <%%fgD%IID% <}55d;;$ ----- r3rLrc t|\}}}nm#t$r}td||||d}~wttf$r}t d||||d}~wt $r}td||d}~wwxYw|5|{ dtj |}nR#t$rEtj tj |d}YnwxYw||||\}}||||cdddS#1swxYwYdS) zyBuild astroid from a source code file (i.e. from an ast). *path* is expected to be a python source file z#Unable to load file {path}: {error})rGrLerrorNzBPython 3 encoding specification error or unknown encoding: {error}z.Wrong or no encoding specified for {filename}.)r.r)r&OSErrorr SyntaxError LookupErrorr UnicodeErrorjoinr modpath_from_file ImportErrorrUrLrVbasename _data_build _post_build) rCrLrGr#rr$excrEbuilders r%rYzAstroidBuilder.file_buildms  %5d%;%; "FHdd   &6     [)   $       &@4    ? ?J!hhx'A$'G'GHHGG"JJJ g..rw/?/?/E/EFFqIGGGJ#..tWdCCOFG##FGX>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sa B4BA B)A;;BE 'B10E1A D=E?D3EEEr$c||||\}}|d|_|||dS)z&Build astroid from source code string.zutf-8)roencode file_bytesrp)rCr$rGrLrErrs r%rTzAstroidBuilder.string_buildsK**4$?? KK00999r3rrrebuilder.TreeRebuilderrcj||_|j||jD]I}|jdkr'|jD]\}}|j| ||J|j D]}| ||j r|j |}|S)zAHandles encoding and delayed nodes after a module has been built. __future__) file_encodingr[ cache_module_import_from_nodesrGnamesfuture_importsaddadd_from_names_to_locals_delayed_assattrdelayed_assattrrBr\)rCrErrr from_nodesymbol_delayeds r%rpzAstroidBuilder._post_builds ( ""6*** 3 5 5I L00!*66IFA)--f5555  ) )) 4 4 4 4/ * *G   ) ) ) )  ! <]33F;;F r3,tuple[nodes.Module, rebuilder.TreeRebuilder]c$ t|d\}}n4#tttf$r}t d|||||d}~wwxYw| t j|}nd}|dr |dd}d}nJ|duoEt j t j |d d k}tj |j ||} | ||||} | | fS) z4Build tree node from data and add some informations.T type_commentsz#Parsing Python code failed: {error})r`rGrLreNzz .__init__irrA) _parse_string TypeError ValueErrorrhrrUrLabspathendswithrVrnr TreeRebuilderr[ visit_module) rCr$rGrLr' parser_modulerq node_filepackagerrrEs r%rozAstroidBuilder._data_builds: "/D"I"I"I D--:{3   $6       --III   K ( ( crclGGGD NG$$RW%5%5d%;%;<._key_funcs?'a 'r3my_listlist[nodes.NodeNG]r=c4|dS)N)key)sort)rrs r% sort_localsz.sort_localss LLYL ' ' ' ' 'r3*N)r'rrr)rrrr=)parentr}do_import_moduler public_names set_localscopelocals)rCr'rnameasnameimportedrs @r%rz'AstroidBuilder.add_from_names_to_localssW  ( ( ( ( ( ( ( ( ( ({{ J H HLD&s{{#4466HH+H$1133BBDK))$555K 1 1 3 3 :4 @AAAAB %%fnd;;; DK--//6v~FGGGG H Hs= A  A nodes.AssignAttrcZ |d}|jD]g}t|tjr t |tjkst |tj kr%|j }|j }t||js}nXt|tjrt|tjtjfr|jr|j }n|j}n#t$$rYwxYw||jg}||vr|jdkr?|r=|ddjdkr|d|R||idS#t.$rYdSwxYw)z_Visit a AssAttr node. This adds name to locals and handle members definition. T)futurerArN)frameexprinferr]rUninferableBasetyper InstancerExceptionInstance_proxiedinstance_attrsr7r)Proxy is_functionrAttributeError setdefaultrinsertappendr)rCr'rinferrediattrsvaluess r%rzAstroidBuilder.delayed_assattrs * JJdJ++E IOO--& (& (h(<==X%.88>>W-FFF#+#4!)!8/$-HH%$%#Hen== 1!#Hu{D>> def x(): >>> def y(): >>> return 1 #@ The return statement will be extracted. >>> class X(object): >>> def meth(self): #@ >>> pass The function object 'meth' will be extracted. Expressions: To extract arbitrary expressions, surround them with the fake function call __(...). After parsing, the surrounded expression will be returned and the whole AST (accessible via the returned node's parent attribute) will look like the function call was never there in the first place. Examples: >>> a = __(1) The const node will be extracted. >>> def x(d=__(foo.bar)): pass The node containing the default argument will be extracted. >>> def foo(a, b): >>> return 0 < __(len(a)) < b The node containing the function call 'len' will be extracted. If no statements or expressions are selected, the last toplevel statement will be returned. If the selected statement is a discard statement, (i.e. an expression turned into a statement), the wrapped expression is returned instead. For convenience, singleton lists are unpacked. :param str code: A piece of Python code that is parsed as a module. Will be passed through textwrap.dedent first. :param str module_name: The name of the module. :returns: The designated node from the parse tree, or a list of nodes. r'rrcHt|tjr|jS|Sr?)r]r Exprr/rs r%_extractzextract_node.._extracts# dEJ ' ' :  r3)rz"Empty tree, cannot extract from itc0g|]}t|Sr.)r)r0rtrees r% z extract_node..s$UUUT,T488UUUr3c&g|] }|Sr.r.)r0r'rs r%rz extract_node..s!666D$666r3cg|]}||Sr?r.)r0r's r%rz extract_node..sMMMtD>>+-IVUUUU_UUU )$//000 (2'''6666I666IMMyMMM !""a''%a(( !!r3c`t||}t|tr|dS|S)zDCall extract_node while making sure that only one value is returned.r)rr]r)rrrets r%_extract_single_noders1 t[ ) )C#t1v Jr3r$rtuple[ast.Module, ParserModule]ct|} ||dz|}nZ#t$rM}|jdtks|std}||dzd}Yd}~nd}~wwxYw||fS)Nr rF)rrrhrMISPLACED_TYPE_ANNOTATION_ERROR)r$rrparsedrqs r%rrs&MBBBM G$$TD[ $NN GGG 8A;9 9 9 9 )>>> $$TD[$FFG =  s- BAA??B)rrrr)r'r(r)r*rr+)rrrLrrrH)rsNT) rrrrrLr*r<r+rrH)r'rrr)r'rrrrr)rs)rrrrrr)rrrrrr)T)r$rrr+rr)0rryrastrUrtypescollections.abcrriortokenizertypingrastroidr r r r r r astroid._astrrastroid.exceptionsrrrastroid.managerrr lazy_importrrrr&r7InspectBuilderr9rrrrrrrr.r3r%rsw  #"""""  ........$$$$$$ IIIIIIIIIIIIIIII88888888WWWWWWWWWW*******dy))G "=""""----XXXXX\0XXXv====! FFFFF,%3%3%3%3P    FS"S"S"S"S"l&*!!!!!!!r3