m
fIc           @   s  d  Z  d k Z d k l Z l Z l Z l Z l Z l Z l Z l	 Z	 l
 Z
 l Z l Z l Z l Z l Z l Z d k Z d d d d d d g Z d	   Z d
 f  d     YZ e   Z d   Z d f  d     YZ d e f d     YZ d e f d     YZ d f  d     YZ e d j o d k Z d k Z e e i d  i    Z! e e! e i" i# e i d  d d  Z$ x@ e$ i%   D]. Z& e$ i' e&  Z( e( Ge( i)   Ge( i*   GHqWn d S(   s2   Interface to the compiler's internal symbol tablesN(   s   USEs
   DEF_GLOBALs	   DEF_LOCALs	   DEF_PARAMs   DEF_STARs   DEF_DOUBLESTARs   DEF_INTUPLEs   DEF_FREEs   DEF_FREE_GLOBALs   DEF_FREE_CLASSs
   DEF_IMPORTs	   DEF_BOUNDs   OPT_IMPORT_STARs   OPT_EXECs   OPT_BARE_EXECt   symtablet   SymbolTablet   newSymbolTablet   Classt   Functiont   Symbolc         C   s&   t  i |  | |  } t | d |  S(   Ni    (   t	   _symtableR    t   codet   filenamet   compile_typet   rawR   (   R   R   R	   R
   (    (    t%   /mit/python/lib/python2.4/symtable.pyR       s    t   SymbolTableFactoryc           B   s#   t  Z d   Z d   Z d   Z RS(   Nc         C   s   t  i   |  _ d  S(   N(   t   weakreft   WeakValueDictionaryt   selft   _SymbolTableFactory__memo(   R   (    (    R   t   __init__   s    c         C   sU   | i t i j o t | |  Sn | i t i j o t | |  Sn t | |  S(   N(	   t   tablet   typeR   t   TYPE_FUNCTIONR   R   t
   TYPE_CLASSR   R   (   R   R   R   (    (    R   t   new   s
    c         C   sS   | | f } |  i i | d   } | d  j o! |  i | |  } |  i | <n | S(   N(	   R   R   t   keyR   R   t   gett   Nonet   objR   (   R   R   R   R   R   (    (    R   t   __call__   s
    !(   t   __name__t
   __module__R   R   R   (    (    (    R   R      s   		c         C   sA   |  t t B@o |  t t Bt B@o t Sn |  t @o t Sn t S(   N(	   t   flagst   USEt   DEF_FREEt	   DEF_LOCALt	   DEF_PARAMt
   DEF_GLOBALt   Truet   DEF_FREE_CLASSt   False(   R   (    (    R   t   is_free&   s
    "c           B   s   t  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   Nc         C   s   | |  _ | |  _ h  |  _ d  S(   N(   t	   raw_tableR   t   _tableR   t	   _filenamet   _symbols(   R   R(   R   (    (    R   R   /   s    		c         C   sp   |  i t j o
 d } n d |  i i } |  i i d j o d | |  i f Sn d | |  i i |  i f Sd  S(   Nt    s   %s t   globals   <%sSymbolTable for module %s>s   <%sSymbolTable for %s in %s>(   R   t	   __class__R   t   kindR   R)   t   nameR*   (   R   R/   (    (    R   t   __repr__4   s    
c         C   s   |  i i t i j o d Sn |  i i t i j o d Sn |  i i t i j o d Sn |  i i d j p t d |  i i  d  S(	   Nt   modulet   functiont   classi   i   i   s   unexpected type: %s(   i   i   i   (   R   R)   R   R   t   TYPE_MODULER   R   t   AssertionError(   R   (    (    R   t   get_type@   s    c         C   s
   |  i i S(   N(   R   R)   t   id(   R   (    (    R   t   get_idJ   s    c         C   s
   |  i i S(   N(   R   R)   R0   (   R   (    (    R   t   get_nameM   s    c         C   s
   |  i i S(   N(   R   R)   t   lineno(   R   (    (    R   t
   get_linenoP   s    c         C   s'   t  |  i i t i j o |  i i  S(   N(   t   boolR   R)   R   R   R   t	   optimized(   R   (    (    R   t   is_optimizedS   s    c         C   s   t  |  i i  S(   N(   R=   R   R)   t   nested(   R   (    (    R   t	   is_nestedW   s    c         C   s   t  |  i i  S(   N(   R=   R   R)   t   children(   R   (    (    R   t   has_childrenZ   s    c         C   s   t  |  i i t t B@ S(   s"   Return true if the scope uses execN(   R=   R   R)   R>   t   OPT_EXECt   OPT_BARE_EXEC(   R   (    (    R   t   has_exec]   s     c         C   s   t  |  i i t @ S(   s&   Return true if the scope uses import *N(   R=   R   R)   R>   t   OPT_IMPORT_STAR(   R   (    (    R   t   has_import_stara   s     c         C   s   |  i i i   S(   N(   R   R)   t   symbolst   keys(   R   (    (    R   t   get_identifierse   s    c         C   sc   |  i i |  } | d  j o@ |  i i | } |  i	 |  } t | | |  } |  i | <n | S(   N(   R   R+   R   R0   t   symR   R)   RI   R   t   _SymbolTable__check_childrent
   namespacesR   (   R   R0   RL   R   RN   (    (    R   t   lookuph   s    !c         C   s.   g  } |  i   D] } | |  i |  q ~ S(   N(   t   _[1]R   RK   t   identRO   (   R   RP   RQ   (    (    R   t   get_symbolsp   s    c         C   sE   g  } |  i i D]- } | i | j o | t | |  i  q q ~ S(   N(   RP   R   R)   RB   t   stR0   R   R*   (   R   R0   RP   RS   (    (    R   t   __check_childrens   s    c         C   s1   g  } |  i i D] } | t | |  i  q ~ S(   N(   RP   R   R)   RB   RS   R   R*   (   R   RP   RS   (    (    R   t   get_childrenx   s    (   R   R   R   R1   R7   R9   R:   R<   R?   RA   RC   RF   RH   RK   RO   RR   RM   RU   (    (    (    R   R   .   s    			
												c           B   sM   t  Z d  Z d  Z d  Z d  Z d   Z d   Z d   Z	 d   Z
 d   Z RS(   Nc         C   sF   t  g  } |  i   D]( } | |  i i |  o | | q q ~  S(   N(   t   tupleRP   R   RK   RQ   t	   test_funcR)   RI   (   R   RW   RP   RQ   (    (    R   t   __idents_matching   s    c         C   s0   |  i d  j o |  i d    |  _ n |  i S(   Nc         C   s   |  t @S(   N(   t   xR"   (   RY   (    (    R   t   <lambda>   s    (   R   t   _Function__paramsR   t   _Function__idents_matching(   R   (    (    R   t   get_parameters   s    c         C   s0   |  i d  j o |  i d    |  _ n |  i S(   Nc         C   s   |  t @S(   N(   RY   t	   DEF_BOUND(   RY   (    (    R   RZ      s    (   R   t   _Function__localsR   R\   (   R   (    (    R   t
   get_locals   s    c            s=   |  i d  j o& t t B  |  i   d    |  _ n |  i S(   Nc            s   |    @S(   N(   RY   t   glob(   RY   (   Ra   (    R   RZ      s    (   R   t   _Function__globalsR   R#   t   DEF_FREE_GLOBALRa   R\   (   R   Ra   (    (   Ra   R   t   get_globals   s    
c         C   s-   |  i d  j o |  i t  |  _ n |  i S(   N(   R   t   _Function__freesR   R\   R'   (   R   (    (    R   t	   get_frees   s    (   R   R   R   R[   R_   Re   Rb   R\   R]   R`   Rd   Rf   (    (    (    R   R   |   s   				c           B   s   t  Z d  Z d   Z RS(   Nc         C   sT   |  i d  j o= h  } x! |  i i D] } d | | i <q# Wt |  |  _ n |  i S(   Ni   (	   R   t   _Class__methodsR   t   dR)   RB   RS   R0   RV   (   R   RS   Rh   (    (    R   t   get_methods   s     (   R   R   R   Rg   Ri   (    (    (    R   R      s   c           B   s   t  Z d  d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   Nc         C   s&   | |  _ | |  _ | p f  |  _ d  S(   N(   R0   R   t   _Symbol__nameR   t   _Symbol__flagsRN   t   _Symbol__namespaces(   R   R0   R   RN   (    (    R   R      s    		c         C   s   d |  i S(   Ns   <symbol '%s'>(   R   Rj   (   R   (    (    R   R1      s    c         C   s   |  i S(   N(   R   Rj   (   R   (    (    R   R:      s    c         C   s   t  |  i t i @ S(   N(   R=   R   Rk   R   R   (   R   (    (    R   t   is_referenced   s    c         C   s   t  |  i t @ S(   N(   R=   R   Rk   R"   (   R   (    (    R   t   is_parameter   s    c         C   s   t  |  i t @p |  i t @ S(   N(   R=   R   Rk   R#   Rc   (   R   (    (    R   t	   is_global   s    c         C   s   t  |  i t @ S(   N(   R=   R   Rk   t   DEF_STAR(   R   (    (    R   t	   is_vararg   s    c         C   s   t  |  i t @ S(   N(   R=   R   Rk   t   DEF_DOUBLESTAR(   R   (    (    R   t   is_keywordarg   s    c         C   s   t  |  i t @ S(   N(   R=   R   Rk   R^   (   R   (    (    R   t   is_local   s    c         C   sJ   |  i t t B@o |  i t t Bt B@o t Sn |  i t @o t Sn t	 S(   N(
   R   Rk   R   R    R!   R"   R#   R$   R%   R&   (   R   (    (    R   R'      s
    (c         C   s   t  |  i t @ S(   N(   R=   R   Rk   t
   DEF_IMPORT(   R   (    (    R   t   is_imported   s    c         C   s   t  |  i t @ S(   N(   R=   R   Rk   R!   (   R   (    (    R   t   is_assigned   s    c         C   s   t  |  i t @ S(   N(   R=   R   Rk   t   DEF_INTUPLE(   R   (    (    R   t   is_in_tuple   s    c         C   s   t  |  i  S(   s  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.
        N(   R=   R   Rl   (   R   (    (    R   t   is_namespace   s    
 c         C   s   |  i S(   s.   Return a list of namespaces bound to this nameN(   R   Rl   (   R   (    (    R   t   get_namespaces   s     c         C   s.   t  |  i  d j o t d  n |  i d S(   s   Returns the single namespace bound to this name.

        Raises ValueError if the name is bound to multiple namespaces.
        i   s$   name is bound to multiple namespacesi    N(   t   lenR   Rl   t
   ValueError(   R   (    (    R   t   get_namespace   s     (   R   R   R   R   R1   R:   Rm   Rn   Ro   Rq   Rs   Rt   R'   Rv   Rw   Ry   Rz   R{   R~   (    (    (    R   R      s    														t   __main__i    i   t   exec(+   t   __doc__R   R   R#   R!   R"   Rp   Rr   Rx   R    Rc   R%   Ru   R^   RG   RD   RE   R   t   __all__R    R   R   R'   R   R   R   R   R   t   ost   syst   opent   argvt   readt   srct   patht   splitt   modRK   RQ   RO   t   infoRt   Rz   (    Rp   R   R   Rc   R"   R    R    R   R%   R   R   Rx   R#   Rr   R   R   RD   R'   R   RQ   Ru   R   R   R   RE   R!   R   RG   R   R   R^   R   (    (    R   t   ?   s(   	a				N!J) 