
bc           @   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   s"   t  j |  | |  } t | |  S(   N(   t	   _symtableR   t   _newSymbolTable(   t   codet   filenamet   compile_typet   top(    (    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+   R-   t   namet   formatR.   (   R   t   kind(    (    s   /usr/lib/python2.7/symtable.pyt   __repr__,   s    			c         C   s|   |  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 sx t d j |  j  j    d  S(	   Nt   modulet   functiont   classi   i   i   s   unexpected type: {0}(   i   i   i   (   R-   R!   R   t   TYPE_MODULER"   R#   t   AssertionErrorR5   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   get_type9   s    c         C   s
   |  j  j S(   N(   R-   t   id(   R   (    (    s   /usr/lib/python2.7/symtable.pyt   get_idC   s    c         C   s
   |  j  j S(   N(   R-   R4   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   get_nameF   s    c         C   s
   |  j  j S(   N(   R-   t   lineno(   R   (    (    s   /usr/lib/python2.7/symtable.pyt
   get_linenoI   s    c         C   s&   t  |  j j t j k o" |  j j  S(   N(   t   boolR-   R!   R   R"   t	   optimized(   R   (    (    s   /usr/lib/python2.7/symtable.pyt   is_optimizedL   s    c         C   s   t  |  j j  S(   N(   RC   R-   t   nested(   R   (    (    s   /usr/lib/python2.7/symtable.pyt	   is_nestedP   s    c         C   s   t  |  j j  S(   N(   RC   R-   t   children(   R   (    (    s   /usr/lib/python2.7/symtable.pyt   has_childrenS   s    c         C   s   t  |  j j t t B@ S(   s"   Return true if the scope uses exec(   RC   R-   RD   R   R   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   has_execV   s    c         C   s   t  |  j j t @ S(   s&   Return true if the scope uses import *(   RC   R-   RD   R   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   has_import_starZ   s    c         C   s   |  j  j j   S(   N(   R-   t   symbolst   keys(   R   (    (    s   /usr/lib/python2.7/symtable.pyt   get_identifiers^   s    c         C   sa   |  j  j |  } | d  k r] |  j j | } |  j |  } t | | |  } |  j  | <n  | S(   N(   R/   R&   R'   R-   RL   t   _SymbolTable__check_childrenR   (   R   R4   t   symt   flagst
   namespaces(    (    s   /usr/lib/python2.7/symtable.pyt   lookupa   s     c         C   s&   g  |  j    D] } |  j |  ^ q S(   N(   RN   RS   (   R   t   ident(    (    s   /usr/lib/python2.7/symtable.pyt   get_symbolsi   s    c         C   s8   g  |  j  j D]' } | j | k r t | |  j  ^ q S(   N(   R-   RH   R4   R   R.   (   R   R4   t   st(    (    s   /usr/lib/python2.7/symtable.pyt   __check_childrenl   s    c         C   s)   g  |  j  j D] } t | |  j  ^ q S(   N(   R-   RH   R   R.   (   R   RV   (    (    s   /usr/lib/python2.7/symtable.pyt   get_childrenq   s    (   R+   R,   R    R7   R=   R?   R@   RB   RE   RG   RI   RJ   RK   RN   RS   RU   RO   RX   (    (    (    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   tupleRN   R-   RL   (   R   t	   test_funcRT   (    (    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>   R1   (   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]      R1   (   t   _Function__localsR'   R   R   R_   (   R   t   test(    (   Ra   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]      R1   (   t   _Function__globalsR'   R   R   R_   (   R   Rc   (    (   Re   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]      R1   (   t   _Function__freesR'   R_   (   R   t   is_free(    (    s   /usr/lib/python2.7/symtable.pyt	   get_frees   s    	N(   R+   R,   R'   R^   Rb   Rh   Rf   R_   R`   Rd   Rg   Rj   (    (    (    s   /usr/lib/python2.7/symtable.pyR   v   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'   R-   RH   R4   RY   (   R   t   dRV   (    (    s   /usr/lib/python2.7/symtable.pyt   get_methods   s    N(   R+   R,   R'   Rk   Rm   (    (    (    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   R4   RQ   RR   (    (    s   /usr/lib/python2.7/symtable.pyR       s    		c         C   s   d j  |  j  S(   Ns   <symbol {0!r}>(   R5   Rn   (   R   (    (    s   /usr/lib/python2.7/symtable.pyR7      s    c         C   s   |  j  S(   N(   Rn   (   R   (    (    s   /usr/lib/python2.7/symtable.pyR@      s    c         C   s   t  |  j t j @ S(   N(   RC   Ro   R   R    (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   is_referenced   s    c         C   s   t  |  j t @ S(   N(   RC   Ro   R   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   is_parameter   s    c         C   s   t  |  j t t f k  S(   N(   RC   Rp   R   R   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt	   is_global   s    c         C   s   t  |  j t k  S(   N(   RC   Rp   R   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   is_declared_global   s    c         C   s   t  |  j t @ S(   N(   RC   Ro   R   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   is_local   s    c         C   s   t  |  j t k  S(   N(   RC   Rp   R   (   R   (    (    s   /usr/lib/python2.7/symtable.pyRi      s    c         C   s   t  |  j t @ S(   N(   RC   Ro   R   (   R   (    (    s   /usr/lib/python2.7/symtable.pyt   is_imported   s    c         C   s   t  |  j t @ S(   N(   RC   Ro   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.
        (   RC   Rq   (   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(   Rq   (   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   lenRq   t
   ValueError(   R   (    (    s   /usr/lib/python2.7/symtable.pyt   get_namespace   s    N(   R+   R,   R'   R    R7   R@   Rr   Rs   Rt   Ru   Rv   Ri   Rw   Rx   Ry   Rz   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   modRN   RT   RS   t   infoRv   Ry   (    (    (    s   /usr/lib/python2.7/symtable.pyt   <module>   s$   j		Q&@)