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__cCsX|jjtjkr dS|jjtjkrdS|jjtjkrdS|jjdvs*Jd |jj¡ƒ‚dS)zwReturn the type of the symbol table. The values retuned are 'class', 'module' and 'function'. ÚmoduleZfunctionÚclass)ééézunexpected type: {0}N)r0r$rZ TYPE_MODULEr%r&r6r!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.)rEr0Únestedr!rrrÚ is_nestedgó zSymbolTable.is_nestedcCrG)z:Return *True* if the block has nested namespaces. )rEr0Úchildrenr!rrrÚ has_childrenlrJzSymbolTable.has_childrencCs |jj ¡S)zKReturn a view object containing the names of symbols in the table. )r0ÚsymbolsÚkeysr!rrrÚget_identifiersqrJzSymbolTable.get_identifierscCsT|j |¡}|dur(|jj|}| |¡}|jjdk}t||||d�}|j|<|S)zLLookup a *name* in the table. Returns a *Symbol* instance. Nr©Ú module_scope)r2r)r0rMÚ_SymbolTable__check_childrenr5r)r"r5ZsymÚflagsÚ namespacesrQrrrÚlookupvs    ÿzSymbolTable.lookupcs‡fdd„ˆ ¡DƒS)zLReturn a list of *Symbol* instances for names in the table. csg|]}ˆ |¡‘qSr)rU©Ú.0Úidentr!rrÚ ˆsz+SymbolTable.get_symbols..)rOr!rr!rÚ get_symbols„szSymbolTable.get_symbolscs‡‡fdd„ˆjjDƒS)Ncs"g|] }|jˆkrt|ˆjƒ‘qSr)r5rr1©rWÚst©r5r"rrrY‹s   þz0SymbolTable.__check_children..©r0rK)r"r5rr]rZ__check_childrenŠs ÿzSymbolTable.__check_childrencs‡fdd„ˆjjDƒS)z3Return a list of the nested symbol tables. csg|]}t|ˆjƒ‘qSr)rr1r[r!rrrY’sÿz,SymbolTable.get_children..r^r!rr!rÚ get_children�s ÿzSymbolTable.get_childrenN)r-r.r/r#r8r>rArBrDrFrIrLrOrUrZrRr_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)r0rMrV©r"Z test_funcrrÚ  s€ÿz-Function.__idents_matching..)ÚtuplerOr`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 re©Zlocsrrrg¯óz%Function.get_locals..)Ú_Function__localsr rrj©r"ÚtestrrprÚ get_localsªó   zFunction.get_localscrm)z3Return a tuple of globals in the function. Ncrnrrore©Zglobrrrg¸rqz&Function.get_globals..)Ú_Function__globalsrrrjrsrrwrÚ get_globals³rvzFunction.get_globalscCrc)z5Return a tuple of nonlocals in the function. NcSrdr)rrerrrrgÀrhz(Function.get_nonlocals..)Ú_Function__nonlocalsrjr!rrrÚ get_nonlocals¼rlzFunction.get_nonlocalscCs$|jdurdd„}| |¡|_|jS)z:Return a tuple of free variables in the function. NcSs|t?t@tkSr)r r r rerrrrgÇrqz$Function.get_frees..)Ú_Function__freesrj)r"Úis_freerrrÚ get_freesÃs  zFunction.get_frees)r-r.r/rirrr|rxrzrjrkruryr{r~rrrrr–s  rc@seZdZdZdd„ZdS)rNcCs6|jduri}|jjD]}d||j<q t|ƒ|_|jS)z9Return a tuple of methods declared in the class. Nr;)Ú_Class__methodsr0rKr5rb)r"Údr\rrrÚ get_methodsÐs    zClass.get_methods)r-r.r/rr�rrrrrÌ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)%rNFrPcCs.||_||_|t?t@|_|pd|_||_dS)Nr)Ú _Symbol__nameÚ_Symbol__flagsr r Ú_Symbol__scopeÚ_Symbol__namespacesÚ_Symbol__module_scope)r"r5rSrTrQrrrr#Ý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!rrrrBçszSymbol.get_namecCst|jtj@ƒS)zBReturn *True* if the symbol is used in its block. )rErƒrrr!rrrÚ is_referencedìszSymbol.is_referencedcCót|jt@ƒS)z4Return *True* if the symbol is a parameter. )rErƒrr!rrrÚ is_parameteròózSymbol.is_parametercCó"t|jttfvp|jo|jt@ƒS)z0Return *True* if the sysmbol is global. )rEr„rrr†rƒrr!rrrÚ is_global÷óÿzSymbol.is_globalcCr‰)z(Return *True* if the symbol is nonlocal.)rErƒrr!rrrÚ is_nonlocalýózSymbol.is_nonlocalcCót|jtkƒS)zOReturn *True* if the symbol is declared global with a global statement.)rEr„rr!rrrÚis_declared_globalr‹zSymbol.is_declared_globalcCrŒ)z.Return *True* if the symbol is local. )rEr„r rr†rƒrr!rrrÚis_localrŽzSymbol.is_localcCr‰)z2Return *True* if the symbol is annotated. )rErƒr r!rrrÚ is_annotated r‹zSymbol.is_annotatedcCr‘)zIReturn *True* if a referenced symbol is not assigned to. )rEr„r r!rrrr}ózSymbol.is_freecCr‰)zQReturn *True* if the symbol is created from an import statement. )rErƒrr!rrrÚ is_importedr•zSymbol.is_importedcCr‰)z)Return *True* if a symbol is assigned to.)rErƒ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. )rEr…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#r8rBrˆrŠr�r�r’r“r”r}r–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ÚmodrOrXrUÚinfoÚprintr“r˜rrrrÚs.D l6` ÿ  ù