
6	Pc           @   s  d  Z  d d l Z d d l m Z m Z m Z m Z m Z m Z m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z d d l Z d d d d d g Z d	   Z d
 d d     YZ e   Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ e d k rd d l Z d d l Z e e j  d  j!   Z" e e" e j# j$ e j  d  d d  Z% x? e% j&   D]. Z' e% j( e'  Z) e) Ge) j*   Ge) j+   GHqWn  d S(   s2   Interface to the compiler's internal symbol tablesiN(   t   USEt
   DEF_GLOBALt	   DEF_LOCALt	   DEF_PARAMt
   DEF_IMPORTt	   DEF_BOUNDt   OPT_IMPORT_STARt   OPT_EXECt   OPT_BARE_EXECt	   SCOPE_OFFt
   SCOPE_MASKt   FREEt   GLOBAL_IMPLICITt   GLOBAL_EXPLICITt   CELLt   LOCALt   symtablet   SymbolTablet   Classt   Functiont   Symbolc         C   sL   t  j |  | |  } x' | j   D] } | j d k r" Pq" q" Wt | |  S(   Nt   top(   t	   _symtableR   t
   itervaluest   namet   _newSymbolTable(   t   codet   filenamet   compile_typet   rawR   (    (    s   /usr/lib/python2.7/symtable.pyR      s
    t   SymbolTableFactoryc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  j   |  _ d  S(   N(   t   weakreft   WeakValueDictionaryt   _SymbolTableFactory__memo(   t   self(    (    s   /usr/lib/python2.7/symtable.pyt   __init__   s    c         C   sK   | j  t j k r t | |  S| j  t j k r> t | |  St | |  S(   N(   t   typeR   t   TYPE_FUNCTIONR   t
   TYPE_CLASSR   R   (   R"   t   tableR   (    (    s   /usr/lib/python2.7/symtable.pyt   new   s
    c         C   sQ   | | f } |  j  j | d   } | d  k rM |  j | |  } |  j  | <n  | S(   N(   R!   t   gett   NoneR(   (   R"   R'   R   t   keyt   obj(    (    s   /usr/lib/python2.7/symtable.pyt   __call__   s
     (   t   __name__t
   __module__R#   R(   R-   (    (    (    s   /usr/lib/python2.7/symtable.pyR      s   		c           B   s   e  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(   c         C   s   | |  _  | |  _ i  |  _ d  S(   N(   t   _tablet	   _filenamet   _symbols(   R"   t	   raw_tableR   (    (    s   /usr/lib/python2.7/symtable.pyR#   *   s    		c         C   sm   |  j  t k r d } n d |  j  j } |  j j d k rM d j | |  j  Sd j | |  j j |  j  Sd  S(   Nt    s   %s t   globals   <{0}SymbolTable for module {1}>s   <{0}SymbolTable for {1} in {2}>(   t	   __class__R   R.   R0   R   t   formatR1   (   R"   t   kind(    (    s   /usr/lib/python2.7/symtable.pyt   __repr__/   s    			c         C   sy   |  j  j t j k r d S|  j  j t j k r2 d S|  j  j t j k rK d S|  j  j d k su t d j |  j  j   d  S(	   Nt   modulet   functiont   classi   i   i   s   unexpected type: {0}(   i   i   i   (   R0   R$   R   t   TYPE_MODULER%   R&   t   AssertionErrorR7   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   get_type<   s    c         C   s
   |  j  j S(   N(   R0   t   id(   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   get_idF   s    c         C   s
   |  j  j S(   N(   R0   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   get_nameI   s    c         C   s
   |  j  j S(   N(   R0   t   lineno(   R"   (    (    s   /usr/lib/python2.7/symtable.pyt
   get_linenoL   s    c         C   s&   t  |  j j t j k o" |  j j  S(   N(   t   boolR0   R$   R   R%   t	   optimized(   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   is_optimizedO   s    c         C   s   t  |  j j  S(   N(   RE   R0   t   nested(   R"   (    (    s   /usr/lib/python2.7/symtable.pyt	   is_nestedS   s    c         C   s   t  |  j j  S(   N(   RE   R0   t   children(   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   has_childrenV   s    c         C   s   t  |  j j t t B@ S(   s"   Return true if the scope uses exec(   RE   R0   RF   R   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   has_execY   s    c         C   s   t  |  j j t @ S(   s&   Return true if the scope uses import *(   RE   R0   RF   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   has_import_star]   s    c         C   s   |  j  j j   S(   N(   R0   t   symbolst   keys(   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   get_identifiersa   s    c         C   sa   |  j  j |  } | d  k r] |  j j | } |  j |  } t | | |  } |  j  | <n  | S(   N(   R2   R)   R*   R0   RN   t   _SymbolTable__check_childrenR   (   R"   R   t   symt   flagst
   namespaces(    (    s   /usr/lib/python2.7/symtable.pyt   lookupd   s     c         C   s&   g  |  j    D] } |  j |  ^ q S(   N(   RP   RU   (   R"   t   ident(    (    s   /usr/lib/python2.7/symtable.pyt   get_symbolsl   s    c         C   s8   g  |  j  j D]' } | j | k r t | |  j  ^ q S(   N(   R0   RJ   R   R   R1   (   R"   R   t   st(    (    s   /usr/lib/python2.7/symtable.pyt   __check_childreno   s    c         C   s)   g  |  j  j D] } t | |  j  ^ q S(   N(   R0   RJ   R   R1   (   R"   RX   (    (    s   /usr/lib/python2.7/symtable.pyt   get_childrent   s    (   R.   R/   R#   R9   R?   RA   RB   RD   RG   RI   RK   RL   RM   RP   RU   RW   RQ   RZ   (    (    (    s   /usr/lib/python2.7/symtable.pyR   (   s    			
												c           B   sM   e  Z d Z d Z d Z d Z d    Z d   Z d   Z	 d   Z
 d   Z RS(   c         C   s9   t  g  |  j   D]" } | |  j j |  r | ^ q  S(   N(   t   tupleRP   R0   RN   (   R"   t	   test_funcRV   (    (    s   /usr/lib/python2.7/symtable.pyt   __idents_matching   s    c         C   s.   |  j  d  k r' |  j d    |  _  n  |  j  S(   Nc         S   s   |  t  @S(   N(   R   (   t   x(    (    s   /usr/lib/python2.7/symtable.pyt   <lambda>   s    (   t   _Function__paramsR*   t   _Function__idents_matching(   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   get_parameters   s    c            sF   |  j  d  k r? t t f     f d   } |  j |  |  _  n  |  j  S(   Nc            s   |  t  ?t @  k S(   N(   R	   R
   (   R^   (   t   locs(    s   /usr/lib/python2.7/symtable.pyR_      s    (   t   _Function__localsR*   R   R   Ra   (   R"   t   test(    (   Rc   s   /usr/lib/python2.7/symtable.pyt
   get_locals   s
    c            sF   |  j  d  k r? t t f     f d   } |  j |  |  _  n  |  j  S(   Nc            s   |  t  ?t @  k S(   N(   R	   R
   (   R^   (   t   glob(    s   /usr/lib/python2.7/symtable.pyR_      s    (   t   _Function__globalsR*   R   R   Ra   (   R"   Re   (    (   Rg   s   /usr/lib/python2.7/symtable.pyt   get_globals   s
    c         C   s4   |  j  d  k r- d   } |  j |  |  _  n  |  j  S(   Nc         S   s   |  t  ?t @t k S(   N(   R	   R
   R   (   R^   (    (    s   /usr/lib/python2.7/symtable.pyR_      s    (   t   _Function__freesR*   Ra   (   R"   t   is_free(    (    s   /usr/lib/python2.7/symtable.pyt	   get_frees   s    	N(   R.   R/   R*   R`   Rd   Rj   Rh   Ra   Rb   Rf   Ri   Rl   (    (    (    s   /usr/lib/python2.7/symtable.pyR   y   s   				c           B   s   e  Z d Z d    Z RS(   c         C   sR   |  j  d  k rK i  } x! |  j j D] } d | | j <q" Wt |  |  _  n  |  j  S(   Ni   (   t   _Class__methodsR*   R0   RJ   R   R[   (   R"   t   dRX   (    (    s   /usr/lib/python2.7/symtable.pyt   get_methods   s    N(   R.   R/   R*   Rm   Ro   (    (    (    s   /usr/lib/python2.7/symtable.pyR      s   c           B   s   e  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 RS(   c         C   s6   | |  _  | |  _ | t ?t @|  _ | p, d |  _ d  S(   N(    (   t   _Symbol__namet   _Symbol__flagsR	   R
   t   _Symbol__scopet   _Symbol__namespaces(   R"   R   RS   RT   (    (    s   /usr/lib/python2.7/symtable.pyR#      s    		c         C   s   d j  |  j  S(   Ns   <symbol {0!r}>(   R7   Rp   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyR9      s    c         C   s   |  j  S(   N(   Rp   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyRB      s    c         C   s   t  |  j t j @ S(   N(   RE   Rq   R   R    (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   is_referenced   s    c         C   s   t  |  j t @ S(   N(   RE   Rq   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   is_parameter   s    c         C   s   t  |  j t t f k  S(   N(   RE   Rr   R   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt	   is_global   s    c         C   s   t  |  j t k  S(   N(   RE   Rr   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   is_declared_global   s    c         C   s   t  |  j t @ S(   N(   RE   Rq   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   is_local   s    c         C   s   t  |  j t k  S(   N(   RE   Rr   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyRk      s    c         C   s   t  |  j t @ S(   N(   RE   Rq   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   is_imported   s    c         C   s   t  |  j t @ S(   N(   RE   Rq   R   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   is_assigned   s    c         C   s   t  |  j  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.
        (   RE   Rs   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   is_namespace   s    c         C   s   |  j  S(   s.   Return a list of namespaces bound to this name(   Rs   (   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   get_namespaces   s    c         C   s,   t  |  j  d k r! t d  n  |  j 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    (   t   lenRs   t
   ValueError(   R"   (    (    s   /usr/lib/python2.7/symtable.pyt   get_namespace   s    N(   R.   R/   R*   R#   R9   RB   Rt   Ru   Rv   Rw   Rx   Rk   Ry   Rz   R{   R|   R   (    (    (    s   /usr/lib/python2.7/symtable.pyR      s   												t   __main__i    i   t   exec(    (,   t   __doc__R   R    R   R   R   R   R   R   R   R   R	   R
   R   R   R   R   R   R   t   __all__R   R   R   t   objectR   R   R   R   R.   t   ost   syst   opent   argvt   readt   srct   patht   splitt   modRP   RV   RU   t   infoRx   R{   (    (    (    s   /usr/lib/python2.7/symtable.pyt   <module>   s$   j		Q&@)