grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|j„,ã@sÀdZddlZddlZddlZgd¢ZiZGdd„dƒZGdd„deƒZGdd „d eƒZ dd d „Z dd d„Z ddd„Z ddd„Z ddd„ZGdd„dejƒZdd„Zdd„Zedkr^eƒdSdS)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_exÚClassÚFunctionc@seZdZdZdd„ZdS)Ú_Objectz+Information about Python class or function.cCsD||_||_||_||_||_||_i|_|dur ||j|<dSdS©N)ÚmoduleÚnameÚfileÚlinenoÚ end_linenoÚparentÚchildren)Úselfrr r r r r ©rú-/opt/alt/python310/lib64/python3.10/pyclbr.pyÚ__init__7sÿz_Object.__init__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrr5s rcs*eZdZdZ dddœ‡fdd„ Z‡ZS)rz7Information about a Python function, including methods.NF©r cs8tƒ ||||||¡||_t|tƒr||j|<dSdSr)ÚsuperrÚis_asyncÚ isinstancerÚmethods)rrr r r r rr ©Ú __class__rrrFs  ÿzFunction.__init__)NF©rrrrrÚ __classcell__rrrrrDó ÿÿrcs*eZdZdZ dddœ‡fdd„ Z‡ZS)rz!Information about a Python class.Nrcs*tƒ ||||||¡|pg|_i|_dSr)rrr)rrr Zsuper_r r r r rrrrPs  zClass.__init__rrrrrrrNr rFc Cst|j||j||||d�S)z*Return a Function after nesting within ob.)r rr )rrr )ÚobZ func_namer r rrrrÚ_nest_functionYsÿr"c Cst|j|||j|||d�S)z'Return a Class after nesting within ob.©r r )rrr )r!Ú class_namer r rrrrÚ _nest_class^sÿr%cCs6i}t||pgƒ ¡D] \}}t|tƒr|||<q |S)z€Return Class objects for the top-level classes in module. This is the original interface, before Functions were added. )Ú _readmoduleÚitemsrr)rÚpathÚresÚkeyÚvaluerrrrds  €rcCst||pgƒS)zâReturn 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. )r&)rr(rrrrpsrc Csv|dur d||f}n|}|tvrt|Si}|tjvr&|dur&|t|<|S| d¡}|dkr`|d|…}||dd…}t|||ƒ}|durMd||f}d|vrXtd |¡ƒ‚t||d|ƒSd} |duri|} n|tj} tj   || ¡} | dur‚t d|›�|d �‚|t|<| j dur�| j |d<z| j  |¡} Wn ttfy¥|YSw| dur¬|S| j  |¡} t||| | ||ƒS) 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. Nz%s.%sÚ.réÚ__path__zNo package named {}zno module named )r )Ú_modulesÚsysÚbuiltin_module_namesÚrfindr&Ú ImportErrorÚformatr(Ú importlibÚutilÚ_find_spec_from_pathÚModuleNotFoundErrorÚsubmodule_search_locationsÚloaderÚ get_sourceÚAttributeErrorÚ get_filenameÚ _create_tree)rr(Ú inpackageÚ fullmoduleÚtreeÚiÚpackageZ submoduler ÚfZ search_pathÚspecÚsourceÚfnamerrrr&zsL        þ r&c@sBeZdZdd„Zdd„Zddœdd„Zd d „Zd d „Zd d„ZdS)Ú_ModuleBrowsercCs(||_||_||_||_||_g|_dSr)r(rAr rr?Ústack)rrr(r rAr?rrrr»s  z_ModuleBrowser.__init__c Csîg}|jD];}t |¡}||jvr| |j|¡qt| d¡}ƒdkr;|�^}}}|tvr:| t| ||¡¡q| |¡q|j rI|j dnd} t |j |j ||j |j| |jd�}| dure||j|j <|j  |¡| |¡|j  ¡dS)Nr,r-éÿÿÿÿr#)ÚbasesÚastZunparserAÚappendÚlenÚsplitr/ÚgetrIrrr r r r Ú generic_visitÚpop) rÚnoderKÚbaser ÚnamesÚ_rZclass_r rrrÚvisit_ClassDefÃs(    € ÿ   z_ModuleBrowser.visit_ClassDefF©rc Csl|jr|jdnd}t|j|j|j|j|||jd�}|dur$||j|j<|j |¡|  |¡|j  ¡dS)NrJr) rIrrr r r r rArMrQrR)rrSrr ZfunctionrrrÚvisit_FunctionDefÜsÿ   z _ModuleBrowser.visit_FunctionDefcCs|j|dd�dS)NTrX)rY)rrSrrrÚvisit_AsyncFunctionDefæsz%_ModuleBrowser.visit_AsyncFunctionDefc Csn|jdkrdS|jD]*}zz t|j|j|jƒWnty't|jgƒYnwWq ttfy4Yq wdS)Nr)Ú col_offsetrUr&r r(r?r3Ú SyntaxError)rrSrrrrÚ visit_Importés   ÿ€ýúz_ModuleBrowser.visit_Importc Cs¼|jdkrdSzd|j}|jr||j7}t||j|jƒ}Wn ttfy*YdSw|jD]-}|j |vrB||j |j |j p@|j <q.|j dkr[|  ¡D]\}}|  d¡rUqK||j |<qKq.dS)Nrr,Ú*rV)r[Úlevelrr&r(r?r3r\rUr rAÚasnamer'Ú startswith)rrSrr Z import_nameZ import_valuerrrÚvisit_ImportFromøs(   ÿ     €ùz_ModuleBrowser.visit_ImportFromN) rrrrrWrYrZr]rbrrrrrHºs  rHcCs&t|||||ƒ}| t |¡¡|jSr)rHZvisitrLÚparserA)r@r(rGrFrAr?Zmbrowserrrrr> sr>c CsVddl}ztjd}Wnt}Y|j |¡r3|j |¡g}|j |¡}| ¡  d¡r2|dd…}ng}t ||ƒ}dd„}t |  ¡|dd �}d }|r©|  ¡}t|tƒrUqIt|d ƒs]d|_t|tƒr|t |j  ¡|dd �}|D]} |j|| _qn| |¡t|tƒr’td  d |j|j|j|j¡ƒnt|tƒr¥td d |j|j|j¡ƒ|sKdSdS)z?Print module output (default this file) for quick visual check.rNr-z.pyéýÿÿÿcSs t|ddƒS)Nr r)Úgetattr)ÚarrrÚ"s z_main..T)r*ÚreverseéÚindentz{}class {} {} {}ú z {}def {} {})Úosr0ÚargvÚ__file__r(ÚexistsÚdirnameÚbasenameÚlowerÚendswithrÚsortedÚvaluesrRrÚlistÚhasattrrjrrÚextendrÚprintr4r rr r) rlÚmodr(rAZ lineno_keyZobjsZ indent_levelÚobjZnew_objsr!rrrÚ_mainsH   €     ÿ  ÿ  îr|Ú__main__)Fr)rrLr0Úimportlib.utilr5Ú__all__r/rrrr"r%rrr&Z NodeVisitorrHr>r|rrrrrÚs(+   @S& ÿ