grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|jé'ã@sXdZddlZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZddlZgd¢Zdd„ZGdd„dƒZeƒZGd d „d ƒZGd d „d eƒZGd d„deƒZGdd„dƒZedkr¨ddlZddlZeejdƒ� Ze  ¡Z!Wdƒn1s~wYee!ej" #ejd¡ddƒZ$e$ %¡D]Z&e$ 'e&¡Z(e)e(e( *¡e( +¡ƒq–dSdS)z2Interface to the compiler's internal symbol tableséN)ÚUSEÚ DEF_GLOBALÚ DEF_NONLOCALÚ DEF_LOCALÚ DEF_PARAMÚ DEF_IMPORTÚ DEF_BOUNDÚ DEF_ANNOTÚ SCOPE_OFFÚ SCOPE_MASKÚFREEÚLOCALÚGLOBAL_IMPLICITÚGLOBAL_EXPLICITÚCELL)ÚsymtableÚ SymbolTableÚClassÚFunctionÚSymbolcCst |||¡}t||ƒS)z« Return the toplevel *SymbolTable* for the source code. *filename* is the name of the file with the code and *compile_type* is the *compile()* mode argument. )Ú _symtablerÚ_newSymbolTable)ÚcodeÚfilenameZ compile_typeÚtop©rú//opt/alt/python310/lib64/python3.10/symtable.pyr s rc@s$eZdZdd„Zdd„Zdd„ZdS)ÚSymbolTableFactorycCst ¡|_dS©N)ÚweakrefZWeakValueDictionaryÚ_SymbolTableFactory__memo©ÚselfrrrÚ__init__szSymbolTableFactory.__init__cCs6|jtjkr t||ƒS|jtjkrt||ƒSt||ƒSr)ÚtyperÚ TYPE_FUNCTIONrÚ TYPE_CLASSrr)r"ÚtablerrrrÚnews     zSymbolTableFactory.newcCs8||f}|j |d¡}|dur| ||¡}|j|<|Sr)r Úgetr()r"r'rÚkeyÚobjrrrÚ__call__ s zSymbolTableFactory.__call__N)Ú__name__Ú __module__Ú __qualname__r#r(r,rrrrrs rc@s|eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)rcCs||_||_i|_dSr)Ú_tableÚ _filenameÚ_symbols)r"Z raw_tablerrrrr#,s zSymbolTable.__init__cCsJ|jtkrd}nd|jj}|jjdkrd ||j¡Sd ||jj|j¡S)NÚz%s rz<{0}SymbolTable for module {1}>z<{0}SymbolTable for {1} in {2}>)Ú __class__rr-r0ÚnameÚformatr1)r"ÚkindrrrÚ__repr__1s   þzSymbolTable.__repr__cCs:|jjtjkr dS|jjtjkrdS|jjtjkrdSdS)zwReturn the type of the symbol table. The values retuned are 'class', 'module' and 'function'. ÚmoduleZfunctionÚclassN)r0r$rZ TYPE_MODULEr%r&r!rrrÚget_type>sÿzSymbolTable.get_typecCó|jjS)z,Return an identifier for the table. )r0Úidr!rrrÚget_idMszSymbolTable.get_idcCr<)zµReturn the table's name. This corresponds to the name of the class, function or 'top' if the table is for a class, function or global respectively. )r0r5r!rrrÚget_nameRszSymbolTable.get_namecCr<)zPReturn the number of the first line in the block for the table. )r0Úlinenor!rrrÚ get_lineno[szSymbolTable.get_linenocCst|jjtjkƒS)zJReturn *True* if the locals in the table are optimizable. )Úboolr0r$rr%r!rrrÚ is_optimizedaszSymbolTable.is_optimizedcCó t|jjƒS)zAReturn *True* if the block is a nested class or function.)rBr0Únestedr!rrrÚ is_nestedgó zSymbolTable.is_nestedcCrD)z:Return *True* if the block has nested namespaces. )rBr0Úchildrenr!rrrÚ has_childrenlrGzSymbolTable.has_childrencCs |jj ¡S)zKReturn a view object containing the names of symbols in the table. )r0ÚsymbolsÚkeysr!rrrÚget_identifiersqrGzSymbolTable.get_identifierscCsT|j |¡}|dur(|jj|}| |¡}|jjdk}t||||d�}|j|<|S)zLLookup a *name* in the table. Returns a *Symbol* instance. Nr©Ú module_scope)r2r)r0rJÚ_SymbolTable__check_childrenr5r)r"r5ZsymÚflagsÚ namespacesrNrrrÚlookupvs    ÿzSymbolTable.lookupcs‡fdd„ˆ ¡DƒS)zLReturn a list of *Symbol* instances for names in the table. csg|]}ˆ |¡‘qSr)rR©Ú.0Úidentr!rrÚ ˆsz+SymbolTable.get_symbols..)rLr!rr!rÚ get_symbols„szSymbolTable.get_symbolscs‡‡fdd„ˆjjDƒS)Ncs"g|] }|jˆkrt|ˆjƒ‘qSr)r5rr1©rTÚst©r5r"rrrV‹s   þz0SymbolTable.__check_children..©r0rH)r"r5rrZrZ__check_childrenŠs ÿzSymbolTable.__check_childrencs‡fdd„ˆjjDƒS)z3Return a list of the nested symbol tables. csg|]}t|ˆjƒ‘qSr)rr1rXr!rrrV’sÿz,SymbolTable.get_children..r[r!rr!rÚ get_children�s ÿzSymbolTable.get_childrenN)r-r.r/r#r8r;r>r?rArCrFrIrLrRrWrOr\rrrrr*s   rc@sPeZdZdZdZdZdZdZdd„Zdd„Z dd„Z dd „Z d d „Z d d „Z dS)rNcst‡‡fdd„ˆ ¡DƒƒS)Nc3s$�|] }ˆˆjj|ƒr|VqdSr)r0rJrS©r"Z test_funcrrÚ  s€ÿz-Function.__idents_matching..)ÚtuplerLr]rr]rZ__idents_matchingŸszFunction.__idents_matchingcCó |jdur | dd„¡|_|jS)z6Return a tuple of parameters to the function. NcSó|t@Sr)r©ÚxrrrÚ§óz)Function.get_parameters..)Ú_Function__paramsÚ_Function__idents_matchingr!rrrÚget_parameters£ó zFunction.get_parameterscó0|jdurttf‰‡fdd„}| |¡|_|jS)z2Return a tuple of locals in the function. Ncó|t?t@ˆvSr©r r rb©Zlocsrrrd¯óz%Function.get_locals..)Ú_Function__localsr rrg©r"ÚtestrrmrÚ get_localsªó   zFunction.get_localscrj)z3Return a tuple of globals in the function. Ncrkrrlrb©Zglobrrrd¸rnz&Function.get_globals..)Ú_Function__globalsrrrgrprrtrÚ get_globals³rszFunction.get_globalscCr`)z5Return a tuple of nonlocals in the function. NcSrar)rrbrrrrdÀrez(Function.get_nonlocals..)Ú_Function__nonlocalsrgr!rrrÚ get_nonlocals¼rizFunction.get_nonlocalscCs$|jdurdd„}| |¡|_|jS)z:Return a tuple of free variables in the function. NcSs|t?t@tkSr)r r r rbrrrrdÇrnz$Function.get_frees..)Ú_Function__freesrg)r"Úis_freerrrÚ get_freesÃs  zFunction.get_frees)r-r.r/rfroryrurwrgrhrrrvrxr{rrrrr–s  rc@seZdZdZdd„ZdS)rNcCs6|jduri}|jjD]}d||j<q t|ƒ|_|jS)z9Return a tuple of methods declared in the class. Né)Ú_Class__methodsr0rHr5r_)r"ÚdrYrrrÚ get_methodsÐs    zClass.get_methods)r-r.r/r}rrrrrrÌs rc@s”eZdZd$ddœdd„Zdd„Zdd „Zd d „Zd d „Zdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zd d!„Zd"d#„ZdS)%rNFrMcCs.||_||_|t?t@|_|pd|_||_dS)Nr)Ú _Symbol__nameÚ_Symbol__flagsr r Ú_Symbol__scopeÚ_Symbol__namespacesÚ_Symbol__module_scope)r"r5rPrQrNrrrr#Ýs   zSymbol.__init__cCs d |j¡S)Nz)r6r€r!rrrr8äs zSymbol.__repr__cCó|jS)z#Return a name of a symbol. )r€r!rrrr?çszSymbol.get_namecCst|jtj@ƒS)zBReturn *True* if the symbol is used in its block. )rBr�rrr!rrrÚ is_referencedìszSymbol.is_referencedcCót|jt@ƒS)z4Return *True* if the symbol is a parameter. )rBr�rr!rrrÚ is_parameteròózSymbol.is_parametercCó"t|jttfvp|jo|jt@ƒS)z0Return *True* if the sysmbol is global. )rBr‚rrr„r�rr!rrrÚ is_global÷óÿzSymbol.is_globalcCr‡)z(Return *True* if the symbol is nonlocal.)rBr�rr!rrrÚ is_nonlocalýózSymbol.is_nonlocalcCót|jtkƒS)zOReturn *True* if the symbol is declared global with a global statement.)rBr‚rr!rrrÚis_declared_globalr‰zSymbol.is_declared_globalcCrŠ)z.Return *True* if the symbol is local. )rBr‚r rr„r�rr!rrrÚis_localrŒzSymbol.is_localcCr‡)z2Return *True* if the symbol is annotated. )rBr�r r!rrrÚ is_annotated r‰zSymbol.is_annotatedcCr�)zIReturn *True* if a referenced symbol is not assigned to. )rBr‚r r!rrrrzózSymbol.is_freecCr‡)zQReturn *True* if the symbol is created from an import statement. )rBr�rr!rrrÚ is_importedr“zSymbol.is_importedcCr‡)z)Return *True* if a symbol is assigned to.)rBr�rr!rrrÚ is_assignedrŽzSymbol.is_assignedcCs t|jƒS)a‹Returns *True* if name binding introduces new namespace. If the name is used as the target of a function or class statement, this will be true. Note that a single name can be bound to multiple objects. If is_namespace() is true, the name may also be bound to other objects, like an int or list, that does not introduce a new namespace. )rBrƒr!rrrÚ is_namespace!s zSymbol.is_namespacecCr…)z.Return a list of namespaces bound to this name)rƒr!rrrÚget_namespaces.szSymbol.get_namespacescCs t|jƒdkr tdƒ‚|jdS)z€Return the single namespace bound to this name. Raises ValueError if the name is bound to multiple namespaces. r|z$name is bound to multiple namespacesr)ÚlenrƒÚ ValueErrorr!rrrÚ get_namespace2s zSymbol.get_namespacer)r-r.r/r#r8r?r†rˆr‹r�r�r‘r’rzr”r•r–r—ršrrrrrÛs" rÚ__main__r|Úexec),Ú__doc__rrrrrrrrr r r r r rrrrÚ__all__rrrrrrrr-ÚosÚsysÚopenÚargvÚfÚreadÚsrcÚpathÚsplitÚmodrLrUrRÚinfoÚprintr‘r–rrrrÚs.D l6` ÿ  ù