bg:dZddlmZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z mZmZddlZddlmZmZddlmZdd lmZeeegejfegeejfZd,dZd-dZGddZGddZGddeejZGddeZ Gdde Z!Gdd e!Z"Gd!d"e!Z#ed#ej$fd.d+Z%dS)/z|Visitor doing some post-processing on the astroid tree. Try to resolve definitions (namespace) dictionary, relationship... ) annotationsN)ABCabstractmethod) Generator)AnyCallableOptional)nodesutil) constants)utilsfuncCallable[[str], nodes.Module]modnamestrreturnnodes.Module | Nonectd|d ||S#tjj$r}t|Yd}~n&d}~wt$rt jYnwxYwdS)Nzparsing z...)printastroid exceptionsAstroidBuildingException Exception traceback print_exc)rrexcs k/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/pyreverse/inspector.py_astroid_wrapperrs !W ! ! !"""tG}}   6 c  4s A+A A+*A+nodenodes.ClassDefGenerator[Any, None, None]c#K tj|dd}n#tjj$rYdSwxYw|d|urdSt}d}tj |D]<}t|tj rd}||vr| ||V=|rtjdS)zEReturn an iterator on interfaces implemented by the given class node.__implements__rNTfutureF)rbasesInstancegetattrr NotFoundErrorframesetr unpack_infer isinstancer UninferableBaseaddInferenceError)r implementsfoundmissingifaces r interfacesr5*s]++D1199:JKKAN   +t$$D00 EEEG#J// eT1 2 2 G     IIe   KKK2 //11122s8=AAc.eZdZdZd d dZd d dZd d Zd S)IdGeneratorMixInz1Mixin adding the ability to generate integer uid.r start_valueintrNonec||_dSNid_countselfr8s r__init__zIdGeneratorMixIn.__init__Bs # c||_dS)zInit the id counter.Nr=r?s r init_counterzIdGeneratorMixIn.init_counterEs # rBc0|xjdz c_|jS)zGenerate a new identifier.r=r@s r generate_idzIdGeneratorMixIn.generate_idIs  }rBN)r)r8r9rr:)rr9)__name__ __module__ __qualname____doc__rArDrHrBrr7r7?s`;;$$$$$$$$$$rBr7c<eZdZdZdddZdd Zdd Zdd ZddZdS)Projectz-A project handle a set of modules / packages.namerc||_d|_d|_g|_i|_|jj|_|jj|_|jj|_|jj|_|jj |_ dS)NrP) rQuidpathmoduleslocals __getitem____iter__valueskeysitemsr@rQs rrAzProject.__init__Rsf # +- /1 ;2 , k( K$ [& rBr nodes.Modulerr:cX||j|j<|j|dSr<)rVrQrUappendr@rs r add_modulezProject.add_module^s,!% DI D!!!!!rBc|j|Sr<)rVr\s r get_modulezProject.get_modulebs{4  rBlist[nodes.Module]c|jSr<)rUrGs r get_childrenzProject.get_childrenes |rBcbd|jdt|dt|jdS)Nz )rQidlenrUrGs r__repr__zProject.__repr__hs5U49UUBtHHUUDL8I8IUUUUrBN)rP)rQrrr]rr:)rQrrr])rrd)rr) rIrJrKrLrArarcrfrjrMrBrrOrOOs77 ' ' ' ' '""""!!!!VVVVVVrBrOc|eZdZdZd#d$d Zd%d Zd&d Zd'dZd(dZd)dZ e d*dZ d+dZ d,dZ d-dZd.d!Zd"S)/LinkeraWalk on the project tree and resolve relationships. According to options the following attributes may be added to visited nodes: * uid, a unique identifier for the node (on astroid.Project, astroid.Module, astroid.Class and astroid.locals_type). Only if the linker has been instantiated with tag=True parameter (False by default). * Function a mapping from locals names to their bounded value, which may be a constant like a string or an integer, or an astroid node (on astroid.Module, astroid.Class and astroid.Function). * instance_attrs_type as locals_type but for klass member attributes (only on astroid.Class) * associations_type as instance_attrs_type but for association relationships * aggregations_type as instance_attrs_type but for aggregations relationships * implements, list of implemented interface _objects_ (only on astroid.Class nodes) FprojectrOtagboolrr:ct|tj|||_||_t |_|jtdSr<) r7rAr LocalsVisitorrornAggregationsHandlerassociations_handlerset_nextOtherAssociationsHandler)r@rnros rrAzLinker.__init__sm!!$''' $$T*** $7$9$9! !**+C+E+EFFFFFrBrc|jr||_|jD]}||dS)zbVisit a pyreverse.utils.Project node. * optionally tag the node with a unique id N)rorHrSrUvisit)r@rmodules r visit_projectzLinker.visit_projectsQ 8 *''))DHl  F JJv      rBr]ct|drdStjt|_g|_|jr||_dSdS)zVisit an astroid.Module node. * set the locals_type mapping * set the depends mapping * optionally tag the node with a unique id locals_typeN) hasattr collections defaultdictlistr|dependsrorHrSr`s r visit_modulezLinker.visit_modules` 4 ' '  F&2488 8 *''))DHHH * *rBr ct|drdStjt|_|jr||_|dD]/}t|dg}| |||_ 0tjt|_ tjt|_ tjt|_t|jD]R}|D]M}t%|t&js1|j|||||NS t1|}|9t||_|jrt5jdt8dSdSg|_dS#t:j$r g|_YdSwxYw)zVisit an astroid.Class node. * set the locals_type and instance_attrs_type mappings * set the implements list and build it * optionally tag the node with a unique id r|NF)recursspecializationszpyreverse will drop support for resolving and displaying implemented interfaces in pylint 3.0. The implementation relies on the '__implements__' attribute proposed in PEP 245, which was rejected in 2006.)r}r~rrr|rorHrS ancestorsr(r_rinstance_attrs_typeaggregations_typeassociations_typetupleinstance_attrsrYr-r Unknownrthandlehandle_assignattr_typer5r1warningswarnDeprecationWarningrr0)r@rbaseobjr assignattrs assignattrifacess rvisit_classdefzLinker.visit_classdefs 4 ' '  F&2488 8 *''))DH~~U~33 6 6G%g/@"EEO  " "4 ( ( (&5G # ##.#:4#@#@ !,!8!>!>!,!8!>!> !4!;!;!=!=>> B BK) B B !*em<<B-44ZFFF// DAAA B  !%%F!"&v,,?M8+ #%% ! ! ! DOOOO !s+AF>5F>>GGnodes.FunctionDefct|drdStjt|_|jr||_dSdS)zVisit an astroid.Function node. * set the locals_type mapping * optionally tag the node with a unique id r|N)r}r~rrr|rorHrSr`s rvisit_functiondefzLinker.visit_functiondefsY 4 ' '  F&2488 8 *''))DHHH * *rBnodes.AssignNamecrt|drdSd|_|j|dvr|d}n|}t|dsut |t jr||nEt |t j r| |n| ||j |j}tt|tj|z|j |j<dS)zFVisit an astroid.AssignName node. handle locals_type _handledNTr$r|)r}rrQr*rootr-r ClassDefr FunctionDefrrr|rr+r infer_node)r@rr*currents rvisit_assignnamezLinker.visit_assignnames" 4 $ $  F 9 $ // / /JJdJ++EEIIKKEum,, )%00 )##E****E5#455 )&&u----!!%(((#DI.'+CLL5;KD;Q;Q,Q'R'R$)$$$rBnodes.AssignAttrparentct|j|j}t|t j|z|j|j<dS)zOHandle an astroid.assignattr node. handle instance_attrs_type N)r+rattrnamerr r)rrrs rrzLinker.handle_assignattr_typesM f0?@@48 e&t,, ,5 5 "4=111rB nodes.Importc|j}|jD]E}tj|d|}|||d|FdS)zKVisit an astroid.Import node. resolve module dependencies rN)rfilenamesrmodutils is_relative_imported_module)r@r context_filerQrelatives r visit_importzLinker.visit_import sj yy{{' J ; ;D'33DG\JJH  ! !$Q : : : : ; ;rBnodes.ImportFromc|j}|j}|!tj||}nd}|jD]}|ddkr|d|d}|ddkr2 tj||}n#t$rYcwxYw||kr| |||dS)zOVisit an astroid.ImportFrom node. resolve module dependencies NFr*.) rrrrrrrfindget_module_part ImportErrorr)r@rbasenamerrrQfullnames rvisit_importfromzLinker.visit_importfroms <yy{{'  #'33HlKKHHHJ @ @DAw#~~"..T!W..H}}S!!B&&&/??,WWHH"H8##%%dHh??? @ @s B$$ B10B1 context_namermod_pathctj|jj}||krdStj||fS)z,Should the module be added to dependencies ?F)osrTdirnamernrrmodule_in_path)r@rr package_dirs rcompute_modulezLinker.compute_module/sGgoodl&788 8 # #5..x+HHHrBnodes.Import | nodes.ImportFromrcL|}|j}|r5d|dddd|}|||r9t |dsg|_|j}||vr||dSdSdS)z8Notify an imported module, used to analyze dependencies.rNrr)rrQjoinsplitrr}rr_)r@rrrryr mod_pathss rrzLinker._imported_module8s{  N((<#5#5c#:#:3B3#?@@MM8MMH   |X 6 6 +69-- $!#Iy((  *****  + + )(rBN)F)rnrOrorprr:)rrOrr:rk)rr rr:)rrrr:)rrrr:rrrr rr:)rrrr:)rrrr:)rrrrrrp)rrrrrrprr:)rIrJrKrLrArzrrrr staticmethodrrrrrrMrBrrmrmls8GGGGG * * * *+!+!+!+!Z * * * *SSSS<   \ ;;;;@@@@0IIII++++++rBrmc>eZdZed dZed d Zd S) AssociationHandlerInterfacehandlerrcdSr<rMr@rs rruz$AssociationHandlerInterface.set_nextJs  rBrrrr r:cdSr<rMr@rrs rrz"AssociationHandlerInterface.handlePs rBNrrrrr)rIrJrKrrurrMrBrrrIsR   ^    ^   rBrc>eZdZUdZded<ddZedd Zd S)AbstractAssociationHandlera Chain of Responsibility for handling types of association, useful to expand in the future if we want to add more distinct associations. Every link of the chain checks if it's a certain type of association. If no association is found it's set as a generic association in `associations_type`. The default chaining behavior is implemented inside the base handler class. r _next_handlerrrc||_|Sr<)rrs rruz#AbstractAssociationHandler.set_nextcs%rBrrrr r:cN|jr|j||dSdSr<)rrrs rrz!AbstractAssociationHandler.handleis6   4   % %dF 3 3 3 3 3 4 4rBNrr)rIrJrKrL__annotations__rurrrMrBrrrUsb  /... 444^444rBrc eZdZdfd ZxZS) rsrrrr rr:ct|jtjtjfr{t|jjt jjrRt|j |j }t|tj|z|j |j <dSt||dSr<)r-rr AnnAssignAssignvaluer node_classesNamer+rrrr rsuperr)r@rrr __class__s rrzAggregationsHandler.handleps dkEOU\#B C C ) K w38I I  )&24=ABBG6:%*400077F $T] 3 3 3 GGNN4 ( ( ( ( (rBr)rIrJrKr __classcell__)rs@rrsrsos= ) ) ) ) ) ) ) ) ) )rBrsceZdZd dZdS) rvrrrr rr:ct|j|j}t|t j|z|j|j<dSr<)r+rrrr r)r@rrrs rrzOtherAssociationsHandler.handle}sGf.t}=>>26wAQRVAWAW7W2X2X ///rBNr)rIrJrKrrMrBrrvrv|s.YYYYYYrBrvzno namefiles list[str] func_wrapper _WrapperFuncT project_name black_listtuple[str, ...]c*tj}t|}|D]s}tj|s3tj|d}nBtj |r!tj |d}n|}||j |}||jp|j |_| ||j} |jr|ddkrytjtj|j |D]6}||j |}| |j| kr!| |7u|S)z1Return a Project from a list of files or modules.rz __init__.pyNrAr)rMANAGERrOrrTexistsrfile_from_modpathrisdirr ast_from_filerrarQpackagerget_module_filesr) rrrrastroid_managerrn somethingfpathast base_names rproject_from_filesrsxoOl##G(( w~~i(( $66ys7K7KLLEE W]]9 % % GLLM::EEEl?8%@@ ; |/sx 3H ; (9>>*55;; )::)): ( (#l?#@%HH;#(i"7"7""3'''' NrB)rrrrrr)rr rr!) rrrrrrrrrrO)&rL __future__rr~rrrabcrrcollections.abcrtypingrrr rr r pylintr pylint.pyreverser rModulerrr5r7rOrrrmrrrsrvDEFAULT_IGNORE_LISTrrMrBrrs  #""""" ########%%%%%%**********""""""(C5%,#67=x ?UUV     2222*         VVVVVVVV:Z+Z+Z+Z+Z+ u2Z+Z+Z+z      #    44444!<4444 ) ) ) ) )4 ) ) )YYYYY9YYY#3!"+"? !!!!!!!rB