
    F\h7                        S r SSKrSSKJrJrJrJrJrJrJrJ	r	J
r
JrJrJrJrJrJr  SSKrSSKJr  / SQrS r " S S5      r\" 5       r " S	 S
\5      r " S S5      r " S S\5      r " S S\5      r " S S5      rS\4/r\R=                  S \" 5       RA                  5        5       5        Sr!\! V s0 s H  n \" 5       U    U _M     sn r"S r#\$S:X  a  SSK%r%\#" \%RL                  SS 5        ggs  sn f )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)StrEnum)symtableSymbolTableTypeSymbolTableClassFunctionSymbolc                 F    [         R                  " XU5      n[        X15      $ )zReturn 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filenamecompile_typetops       /usr/lib/python3.13/symtable.pyr   r      s!     

T\
:C3))    c                   &    \ rS rSrS rS rS rSrg)SymbolTableFactory   c                 8    [         R                  " 5       U l        g N)weakrefWeakValueDictionary_SymbolTableFactory__memoselfs    r    __init__SymbolTableFactory.__init__   s    113r!   c                     UR                   [        R                  :X  a  [        X5      $ UR                   [        R                  :X  a  [        X5      $ [        X5      $ r&   )typer   TYPE_FUNCTIONr   
TYPE_CLASSr   r   )r+   tabler   s      r    newSymbolTableFactory.new   sG    ::000E,,::---))5++r!   c                     X4nU R                   R                  US 5      nUc  U R                  X5      =o@R                   U'   U$ r&   )r)   getr3   )r+   r2   r   keyobjs        r    __call__SymbolTableFactory.__call__!   sA    okkooc4(;%)XXe%>>C++c"
r!   )__memoN)__name__
__module____qualname____firstlineno__r,   r3   r9   __static_attributes__ r!   r    r#   r#      s    4,r!   r#   c                   0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)r   +   modulefunctionclass
annotationz
type aliasztype parametersztype variablerA   N)r<   r=   r>   r?   MODULEFUNCTIONCLASS
ANNOTATION
TYPE_ALIASTYPE_PARAMETERSTYPE_VARIABLEr@   rA   r!   r    r   r   +   s%    FHEJJ'O#Mr!   r   c                   h    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSrg)r   5   c                 *    Xl         X l        0 U l        g r&   )_table	_filename_symbols)r+   	raw_tabler   s      r    r,   SymbolTable.__init__7   s    !r!   c                 .   U R                   [        :X  a  SnOSU R                   R                  -  nU R                  R                  S:X  a  SR                  XR                  5      $ SR                  UU R                  R                  U R                  5      $ )N z%s r   z<{0}SymbolTable for module {1}>z<{0}SymbolTable for {1} in {2}>)	__class__r   r<   rR   nameformatrS   )r+   kinds     r    __repr__SymbolTable.__repr__<   sy    >>[(D4>>222D;;u$4;;D..QQ4;;D<@KK<L<L<@NNL Lr!   c                 N   U R                   R                  [        R                  :X  a  [        R
                  $ U R                   R                  [        R                  :X  a  [        R                  $ U R                   R                  [        R                  :X  a  [        R                  $ U R                   R                  [        R                  :X  a  [        R                  $ U R                   R                  [        R                  :X  a  [        R                  $ U R                   R                  [        R                  :X  a  [        R                  $ U R                   R                  [        R                   :X  a  [        R"                  $  SU R                   R                   35       e)zvReturn the type of the symbol table.

The value returned is one of the values in
the ``SymbolTableType`` enumeration.
zunexpected type: )rR   r/   r   TYPE_MODULEr   rH   r0   rI   r1   rJ   TYPE_ANNOTATIONrK   TYPE_TYPE_ALIASrL   TYPE_TYPE_PARAMETERSrM   TYPE_TYPE_VARIABLErN   r*   s    r    get_typeSymbolTable.get_typeI   s    ;;y444")));;y666"+++;;y333"(((;;y888"---;;y888"---;;y==="222;;y;;;"000<)$++*:*:);<<ur!   c                 .    U R                   R                  $ )z,Return an identifier for the table.
        )rR   idr*   s    r    get_idSymbolTable.get_id_   s     {{~~r!   c                 .    U R                   R                  $ )zReturn 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.
)rR   rZ   r*   s    r    get_nameSymbolTable.get_named   s     {{r!   c                 .    U R                   R                  $ )z@Return the number of the first line in the
block for the table.
)rR   linenor*   s    r    
get_linenoSymbolTable.get_linenom   s     {{!!!r!   c                 b    [        U R                  R                  [        R                  :H  5      $ )z:Return *True* if the locals in the table
are optimizable.
)boolrR   r/   r   r0   r*   s    r    is_optimizedSymbolTable.is_optimizeds   s$     DKK$$	(?(??@@r!   c                 @    [        U R                  R                  5      $ )z9Return *True* if the block is a nested class
or function.)rs   rR   nestedr*   s    r    	is_nestedSymbolTable.is_nestedy   s     DKK&&''r!   c                 @    [        U R                  R                  5      $ )z:Return *True* if the block has nested namespaces.
        )rs   rR   childrenr*   s    r    has_childrenSymbolTable.has_children~   s     DKK(())r!   c                 J    U R                   R                  R                  5       $ )zKReturn a view object containing the names of symbols in the table.
        )rR   symbolskeysr*   s    r    get_identifiersSymbolTable.get_identifiers   s     {{""''))r!   c                     U R                   R                  U5      nUc\  U R                  R                  U   nU R	                  U5      nU R                  R
                  S:H  n[        XUUS9=o R                   U'   U$ )z<Lookup a *name* in the table.

Returns a *Symbol* instance.
r   module_scope)rT   r6   rR   r   _SymbolTable__check_childrenrZ   r   )r+   rZ   symflags
namespacesr   s         r    lookupSymbolTable.lookup   s{    
 mm%;KK''-E..t4J KK,,5L(.tJ<H)J JC--%
r!   c                 j    U R                  5        Vs/ s H  oR                  U5      PM     sn$ s  snf )z<Return a list of *Symbol* instances for
names in the table.
)r   r   )r+   idents     r    get_symbolsSymbolTable.get_symbols   s.     150D0D0FG0FuE"0FGGGs   0c                     U R                   R                   Vs/ s H*  nUR                  U:X  d  M  [        X R                  5      PM,     sn$ s  snf r&   )rR   r{   rZ   r   rS   )r+   rZ   sts      r    __check_childrenSymbolTable.__check_children   sG    ++..$.B77d? 4NN3.$ 	$ $s
   AAc                     U R                   R                   Vs/ s H  n[        XR                  5      PM     sn$ s  snf )z3Return a list of the nested symbol tables.
        )rR   r{   r   rS   )r+   r   s     r    get_childrenSymbolTable.get_children   s<     ++..0.B  NN3.0 	0 0s   ;)rS   rT   rR   N)r<   r=   r>   r?   r,   r]   re   ri   rl   rp   rt   rx   r|   r   r   r   r   r   r@   rA   r!   r    r   r   5   sK    
L=,
 "A(
*
*
H$
0r!   r   c                   L    \ rS rSrSrSrSrSrSrS r	S r
S rS rS rS rS	rg)
r      Nc                 N   ^ ^ [        U U4S jT R                  5        5       5      $ )Nc              3   t   >#    U  H-  nT" TR                   R                  U   5      (       d  M)  Uv   M/     g 7fr&   )rR   r   ).0r   r+   	test_funcs     r    	<genexpr>-Function.__idents_matching.<locals>.<genexpr>   s1      ?(>u!$++"5"5e"<= U(>s   (8	8)tupler   )r+   r   s   ``r    __idents_matchingFunction.__idents_matching   s%     ?(<(<(> ? ? 	?r!   c                 b    U R                   c  U R                  S 5      U l         U R                   $ )z6Return a tuple of parameters to the function.
        c                     U [         -  $ r&   )r   xs    r    <lambda>)Function.get_parameters.<locals>.<lambda>   s    A	Mr!   )_Function__params_Function__idents_matchingr*   s    r    get_parametersFunction.get_parameters   s+     ==  223IJDM}}r!   c                    ^ U R                   c(  [        [        4mU4S jnU R                  U5      U l         U R                   $ )z2Return a tuple of locals in the function.
        c                 *   > U [         -	  [        -  T;   $ r&   r   r   )r   locss    r    r   %Function.get_locals.<locals>.<lambda>   s    qI~;Dr!   )_Function__localsr   r   r   )r+   testr   s     @r    
get_localsFunction.get_locals   s9     == 4=DDD 2248DM}}r!   c                    ^ U R                   c(  [        [        4mU4S jnU R                  U5      U l         U R                   $ )z3Return a tuple of globals in the function.
        c                 *   > U [         -	  [        -  T;   $ r&   r   )r   globs    r    r   &Function.get_globals.<locals>.<lambda>   s    a9n
:tCr!   )_Function__globalsr   r   r   )r+   r   r   s     @r    get_globalsFunction.get_globals   s:     >>!#_5DCD!33D9DN~~r!   c                 b    U R                   c  U R                  S 5      U l         U R                   $ )z5Return a tuple of nonlocals in the function.
        c                     U [         -  $ r&   )r   r   s    r    r   (Function.get_nonlocals.<locals>.<lambda>   s	    q<?Or!   )_Function__nonlocalsr   r*   s    r    get_nonlocalsFunction.get_nonlocals   s0     ##556OPDr!   c                 f    U R                   c  S nU R                  U5      U l         U R                   $ )z:Return a tuple of free variables in the function.
        c                 0    U [         -	  [        -  [        :H  $ r&   )r   r   r   r   s    r    r   $Function.get_frees.<locals>.<lambda>   s    i: =$Fr!   )_Function__freesr   )r+   is_frees     r    	get_freesFunction.get_frees   s/     <<FG11':DL||r!   )__frees	__globals__locals__nonlocals__params)r<   r=   r>   r?   r   r   r   r   r   r   r   r   r   r   r   r@   rA   r!   r    r   r      s;     HHGIK? r!   r   c                       \ rS rSrSrS rSrg)r      Nc                 ~  ^  T R                   Gc#  0 nU 4S jnT R                  R                   H  nU" UR                  5      (       d  M  UR                  =[
        R                  :X  a3    UR                  S:X  a  SUR                  ;   a  M^  SXR                  '   Mn  [
        R                  :X  d  M  UR                  nUR                   HR  nUR                  U:X  d  M  UR                  [
        R                  :X  d  M5  US:w  d  SUR                  ;  d   eSX'     M     M     [        U5      T l         T R                   $ )z9Return a tuple of methods declared in the class.
        c                 ~   > TR                   R                  R                  U S5      nU[        -	  [        -  [
        :H  $ )Nr   )rR   r   r6   r   r   r   )r   r   r+   s     r    is_local_symbol*Class.get_methods.<locals>.is_local_symbol   s4    ++//q9)+z9eCCr!   genexprz.0   )
_Class__methodsrR   r{   rZ   r/   r   r0   varnamesrc   r   )r+   dr   r   
scope_namecs   `     r    get_methodsClass.get_methods   s     >>!AD kk**"277++''4Y44  "ww)38K ()*AggJ&;; *,J%'[[#$66Z#7AFFiF]F]<] ,6+BdRSR\R\F\$\+\45AM$) &1 +4 #1XDN~~r!   )	__methods)r<   r=   r>   r?   r   r   r@   rA   r!   r    r   r      s    I%r!   r   c                       \ rS rSrSSS.S jjrS rS rS rS	 rS
 r	S r
S rS rS rS rS rS rS rS rS rS rS rSrg)r   i
  NFr   c                r    Xl         X l        U[        -	  [        -  U l        U=(       d    SU l        X@l        g )NrA   )_Symbol__name_Symbol__flagsr   r   _Symbol__scope_Symbol__namespaces_Symbol__module_scope)r+   rZ   r   r   r   s        r    r,   Symbol.__init__  s0    *j8&,"*r!   c                     SR                  U R                  5       5      nSU R                  < SU R                  5        SU S3$ )N|z<symbol : , >)join
_flags_strr   
_scope_str)r+   	flags_strs     r    r]   Symbol.__repr__  s>    HHT__./	$++4??+<*=R	{!LLr!   c                 x    [         R                  U R                  5      =(       d    [        U R                  5      $ r&   )_scopes_value_to_namer6   r   strr*   s    r    r   Symbol._scope_str  s%    $((6K#dll:KKr!   c              #   \   #    [          H  u  pU R                  U-  U:X  d  M  Uv   M      g 7fr&   )_flagsr   )r+   flagname	flagvalues      r    r   Symbol._flags_str  s(     #)H||i'94 $*s   ,	,c                     U R                   $ )z#Return a name of a symbol.
        )r   r*   s    r    rl   Symbol.get_name  s     {{r!   c                 N    [        U R                  [        R                  -  5      $ )z2Return *True* if the symbol is used in
its block.
)rs   r   r   r   r*   s    r    is_referencedSymbol.is_referenced$  s     DLL9==011r!   c                 :    [        U R                  [        -  5      $ )z4Return *True* if the symbol is a parameter.
        )rs   r   r   r*   s    r    is_parameterSymbol.is_parameter*       DLL9,--r!   c                     [        U R                  [        [        4;   =(       d&    U R                  =(       a    U R
                  [        -  5      $ )z/Return *True* if the symbol is global.
        )rs   r   r   r   r   r   r	   r*   s    r    	is_globalSymbol.is_global/  s@     DLL_o$FF J++Hy0HK 	Kr!   c                 :    [        U R                  [        -  5      $ )z(Return *True* if the symbol is nonlocal.)rs   r   r   r*   s    r    is_nonlocalSymbol.is_nonlocal5  s    DLL</00r!   c                 :    [        U R                  [        :H  5      $ )zGReturn *True* if the symbol is declared global
with a global statement.)rs   r   r   r*   s    r    is_declared_globalSymbol.is_declared_global9  s     DLLO344r!   c                     [        U R                  [        [        4;   =(       d&    U R                  =(       a    U R
                  [        -  5      $ )z.Return *True* if the symbol is local.
        )rs   r   r   r   r   r   r	   r*   s    r    is_localSymbol.is_local>  s?     DLLUDM1 J++Hy0HK 	Kr!   c                 :    [        U R                  [        -  5      $ )z2Return *True* if the symbol is annotated.
        )rs   r   r
   r*   s    r    is_annotatedSymbol.is_annotatedD  r  r!   c                 :    [        U R                  [        :H  5      $ )z9Return *True* if a referenced symbol is
not assigned to.
)rs   r   r   r*   s    r    r   Symbol.is_freeI  s     DLLD())r!   c                 :    [        U R                  [        -  5      $ )zAReturn *True* if the symbol is created from
an import statement.
)rs   r   r   r*   s    r    is_importedSymbol.is_importedO  s     DLL:-..r!   c                 :    [        U R                  [        -  5      $ )z)Return *True* if a symbol is assigned to.)rs   r   r   r*   s    r    is_assignedSymbol.is_assignedU  s    DLL9,--r!   c                 ,    [        U R                  5      $ )aS  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.
)rs   r   r*   s    r    is_namespaceSymbol.is_namespaceY  s     D%%&&r!   c                     U R                   $ )z.Return a list of namespaces bound to this name)r   r*   s    r    get_namespacesSymbol.get_namespacesf  s       r!   c                     [        U R                  5      S:X  a  [        S5      e[        U R                  5      S:  a  [        S5      eU R                  S   $ )zReturn the single namespace bound to this name.

Raises ValueError if the name is bound to multiple namespaces
or no namespace.
r   z#name is not bound to any namespacesr   z$name is bound to multiple namespaces)lenr   
ValueErrorr*   s    r    get_namespaceSymbol.get_namespacej  sS     t  !Q&BCC""#a'CDD$$Q''r!   )__flags__module_scope__name__namespaces__scoper&   )r<   r=   r>   r?   r,   r]   r   r   rl   r   r   r  r  r	  r  r  r   r  r  r  r  r"  r@   rA   r!   r    r   r   
  sg    +U +ML

2.
K15
K.
*/.'!(r!   r   r   c              #   Z   #    U  H!  oS    R                  S5      (       d  M  Uv   M#     g7f)r   DEF_N)
startswith)r   kvs     r    r   r   y  s#     I,R10@0@0Hbb,s   +	+)r   r   r   r   r   c                    ^ SS K nSU4S jjmU =(       d    S/ H`  nUS:X  a  UR                  R                  5       nSnO%[        US5       nUR                  5       nS S S 5        [	        WUS5      nT" U5        Mb     g ! , (       d  f       N(= f)Nr   c           
      |  > SU-  nU R                  5       (       a  SOSnU R                  5       S:X  a  SU R                  < 3nOU R                  5       < n[	        U SU U R                  5        SU S35        U R                  5        H  nU R                  U5      nS	R                  UR                  5       5      R                  5       n[	        SU UR                  5       R                  5        S
UR                  5       < SU 35        M     [	        5         U R                  5        H  nT	" XS-   5        M     g )Nz    znested rX   rD   z
from file zsymbol table for  :r   z symbol r   r   )rx   re   rS   rl   printr   r   r   r   lowerr   r   )
r2   levelindentrw   whatr   symbolr   table2print_symbolss
            r    r8  main.<locals>.print_symbols  s   %#oo//R>>x'23Dnn&)D)&%..2B1C1TF!LM**,E\\%(FIIf//1288:ED!2!2!4!:!:!< =XfooFWEZZ\]b\cde - 	((*F&!), +r!   -z<stdin>rbexec)r   )sysstdinreadopenr   )argsr=  r   srcfmodr8  s         @r    mainrE  ~  sv    -" MSEMs?)).."C Hh%ffh &sHf-c "
 &%s   A??
B	__main__r   )'__doc__r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r'   enumr   __all__r   r#   r   r   r   r   r   r   r   extendglobalsitems_scopes_namesr   rE  r<   r=  argv)ns   0r    <module>rP     s   8 4 4 4 4 4  
W* $ %&$g $p0 p0f3{ 3l)K )Xk( k(\ #, I79??,I IO2?@-Q1q-@ < z!" C As   6C2