Qf,dZddlZddlZddlZgdZiZGddZGddeZGdd eZ dd Z dd Z dd Z dd Z ddZGddejZdZdZedk(reyy)aParse a Python module and describe its classes and functions. Parse enough of a Python file to recognize imports and class and function definitions, and to find out the superclasses of a class. The interface consists of a single function: readmodule_ex(module, path=None) where module is the name of a Python module, and path is an optional list of directories where the module is to be searched. If present, path is prepended to the system search path sys.path. The return value is a dictionary. The keys of the dictionary are the names of the classes and functions defined in the module (including classes that are defined via the from XXX import YYY construct). The values are instances of classes Class and Function. One special key/value pair is present for packages: the key '__path__' has a list as its value which contains the package search path. Classes and Functions have a common superclass: _Object. Every instance has the following attributes: module -- name of the module; name -- name of the object; file -- file in which the object is defined; lineno -- line in the file where the object's definition starts; end_lineno -- line in the file where the object's definition ends; parent -- parent of this object, if any; children -- nested objects contained in this object. The 'children' attribute is a dictionary mapping names to objects. Instances of Function describe functions with the attributes from _Object, plus the following: is_async -- if a function is defined with an 'async' prefix Instances of Class describe classes with the attributes from _Object, plus the following: super -- list of super classes (Class instances if possible); methods -- mapping of method names to beginning line numbers. If the name of a super class is not recognized, the corresponding entry in the list of super classes is not a class instance but a string giving the name of the super class. Since import statements are recognized and imported modules are scanned as well, this shouldn't happen often. N) readmodule readmodule_exClassFunctionceZdZdZdZy)_Objectz+Information about Python class or function.c||_||_||_||_||_||_i|_|||j |<yyN)modulenamefilelineno end_linenoparentchildren)selfr r r rrrs -/opt/alt/python312/lib64/python3.12/pyclbr.py__init__z_Object.__init__7sL    $   $(FOOD ! N)__name__ __module__ __qualname____doc__rrrrr5s 1 )rrc,eZdZdZ dddfd ZxZS)rz7Information about a Python function, including methods.Nrc|t|||||||||_t|tr||j |<yyr )superris_async isinstancermethods) rr r r rrrr __class__s rrzFunction.__init__Fs> tVZH  fe $#)FNN4  %r)NFrrrrr __classcell__r"s@rrrDs=',*<@**rrc,eZdZdZ dddfd ZxZS)rz!Information about a Python class.NrcRt||||||||xsg|_i|_yr )rrr!) rr r super_r rrrr"s rrzClass.__init__Ps, tVZH\r  rr r#r%s@rrrNs',0rrc Nt|j||j||||S)z*Return a Function after nesting within ob.)rrr)rr r )ob func_namerrrs r_nest_functionr,Ys( BIIy"''6Z IIrc Nt|j|||j|||S)z'Return a Class after nesting within ob.rr)rr r )r* class_namerrrs r _nest_classr0^s& Jrwwz 33rci}t||xsgjD]\}}t|ts|||<|S)zReturn Class objects for the top-level classes in module. This is the original interface, before Functions were added. ) _readmoduleitemsr r)r pathreskeyvalues rrrdsE C!&$*"5;;= U eU #CH> Jrc"t||xsgS)zReturn a dictionary with all functions and classes in module. Search for module in PATH + sys.path. If possible, include imported superclasses. Do this by reading source, without importing (and executing) it. )r2)r r4s rrrps vtzr **rc||d|}n|}|tvr t|Si}|tjvr | |t|<|S|jd}|dk\rQ|d|}||dzd}t |||}||d|}d|vrt dj |t ||d|Sd} ||} n|tjz} tjj|| } | td|||t|<| j| j|d< | jj|} | |S| jj!|} t#||| | ||S#tt f$r|cYSwxYw) a.Do the hard work for readmodule[_ex]. If inpackage is given, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and path is combined with sys.path. N.r__path__zNo package named {}zno module named )r )_modulessysbuiltin_module_namesrfindr2 ImportErrorformatr4 importlibutil_find_spec_from_pathModuleNotFoundErrorsubmodule_search_locationsloader get_sourceAttributeError get_filename _create_tree)r r4 inpackage fullmoduletreeipackage submodulerf search_pathspecsourcefnames rr2r2zs )62  X ## D)))i.?   SAAv!*1Q34L WdI6  !*G4GV#3::7CD D9fZ&8'BB A SXXo >> . .z; GD |!$4ZN"C*UUHZ &&2::Z'' 3 >K KK $ $Z 0E  D%y II K ( sE!!E54E5c6eZdZdZdZdddZdZdZdZy ) _ModuleBrowsercX||_||_||_||_||_g|_yr )r4rOr r rMstack)rr r4r rOrMs rrz_ModuleBrowser.__init__s,    " rc g}|jD]}tj|}||jvr|j |j|Et |j dx}dkDr8|^}}}|tvss|j t|j|||j ||jr|jdnd} t|j|j||j|j| |j}| ||j|j<|jj ||j!||jj#y)Nr:r;r.)basesastunparserOappendlensplitr=getr[rr r r rr generic_visitpop) rnoder^baser names_r class_rs rvisit_ClassDefz_ModuleBrowser.visit_ClassDefs'JJD;;t$Dtyy  TYYt_-djjo-U.2&+"FFX%LL&!1!5!5fd!CD T"$(::B4t{{DIIudii$B >#)DIIdii  &! 4  rFrc |jr|jdnd}t|j|j|j|j |||j }|||j|j<|jj||j||jjy)Nr]r) r[rr r r rrrOrarerf)rrgrrfunctions rvisit_FunctionDefz _ModuleBrowser.visit_FunctionDefs#'::B4DKKDIIt{{"HJ >#+DIIdii  (# 4  rc*|j|dy)NTrm)rp)rrgs rvisit_AsyncFunctionDefz%_ModuleBrowser.visit_AsyncFunctionDefs td3rc|jdk7ry|jD]/} t|j|j|j 1y#t $rt|jgY$wxYw#t tf$rYiwxYw)Nr) col_offsetrir2r r4rMrA SyntaxError)rrgr s r visit_Importz_ModuleBrowser.visit_Importsy ??a  jjF 1 TYYG!#1 R01-  s)+AA2/A51A22A55BBc |jdk7ry d|jz}|jr||jz }t||j|j }|jD]}|j|vr5||j|j|jxs |j<F|jdk(sV|jD]&\}}|jdr||j|<(y#t tf$rYywxYw)Nrr:*rj)rtlevelr r2r4rMrArurir rOasnamer3 startswith)rrgr r import_name import_values rvisit_ImportFromz_ModuleBrowser.visit_ImportFroms ??a   4::%F{{$++% DNNCFJJDyyF"6z_main.."s 71h2rT)r6reverseindentz{}class {} {} {} z {}def {} {})osr>argv__file__r4existsdirnamebasenamelowerendswithrsortedvaluesrfr listhasattrrrrextendrprintrBr rrr) rmodr4rO lineno_keyobjs indent_levelobjnew_objsr*s r_mainrs hhqk ww~~c$%ggs# 99;   &cr(C d #D2J $++-Z >DL hhj c4 sH%CJ c7 #cll113",dimportlib.utilrC__all__r=rrrr,r0rrr2 NodeVisitorrYrLrrrrrrs)V  >  ) )*w*GI 3 +=J@P:S__P:f $PL z Gr