Your IP : 3.15.18.73


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/symtable.cpython-310.pyc

o

6��f�'�@sXdZddlZddlmZmZmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZddlZgd�Zdd�ZGdd�d�Ze�ZGd	d
�d
�ZGdd�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|jtjkrt||�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
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�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$rZTYPE_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�
<listcomp>�sz+SymbolTable.get_symbols.<locals>.<listcomp>)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.<locals>.<listcomp>�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.<locals>.<listcomp>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	�Zd
d�Zdd
�Z
dS)rNcst��fdd����D��S)Nc3s$�|]
}��jj|�r|VqdSr)r0rMrV�r"Z	test_funcrr�	<genexpr>�s��z-Function.__idents_matching.<locals>.<genexpr>)�tuplerOr`rr`rZ__idents_matching�szFunction.__idents_matchingcC� |jdur
|�dd��|_|jS)z6Return a tuple of parameters to the function.
        NcS�|t@Sr)r��xrrr�<lambda>��z)Function.get_parameters.<locals>.<lambda>)�_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
rre�Zlocsrrrg��z%Function.get_locals.<locals>.<lambda>)�_Function__localsr
rrj�r"�testrrpr�
get_locals��

zFunction.get_localscrm)z3Return a tuple of globals in the function.
        Ncrnrrore�Zglobrrrg�rqz&Function.get_globals.<locals>.<lambda>)�_Function__globalsrrrjrsrrwr�get_globals�rvzFunction.get_globalscCrc)z5Return a tuple of nonlocals in the function.
        NcSrdr)rrerrrrg�rhz(Function.get_nonlocals.<locals>.<lambda>)�_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
rrrerrrrg�rqz$Function.get_frees.<locals>.<lambda>)�_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<qt|�|_|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�Zdd�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<symbol {0!r}>)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�dkrtd��|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
rrr
rrrr�__all__rrrrrrrr-�os�sys�open�argv�f�read�src�path�split�modrOrXrU�info�printr�r�rrrr�<module>s.D	l6`
�
�

?>