Ñò
ïžòKc           @   sÈ  d  Z  d d k Z d 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 d d k Z d d k 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 j o� d d k Z d 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 tablesiÿÿÿÿN(   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   symtablet   SymbolTablet   Classt   Functiont   Symbolc         C   sN   t  i |  | | ƒ } x) | i ƒ  D] } | i d j o Pq" q" Wt | | ƒ S(   Nt   top(   t	   _symtableR   t
   itervaluest   namet   _newSymbolTable(   t   codet   filenamet   compile_typet   rawR   (    (    s   scripts/common/Lib/symtable.pyR      s     	t   SymbolTableFactoryc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   t  i ƒ  |  _ d  S(   N(   t   weakreft   WeakValueDictionaryt   _SymbolTableFactory__memo(   t   self(    (    s   scripts/common/Lib/symtable.pyt   __init__   s    c         C   sO   | i  t i j o t | | ƒ S| i  t i j o t | | ƒ St | | ƒ S(   N(   t   typeR   t   TYPE_FUNCTIONR   t
   TYPE_CLASSR   R   (   R    t   tableR   (    (    s   scripts/common/Lib/symtable.pyt   new   s
    c         C   sS   | | f } |  i  i | d  ƒ } | d  j o! |  i | | ƒ } |  i  | <n | S(   N(   R   t   gett   NoneR&   (   R    R%   R   t   keyt   obj(    (    s   scripts/common/Lib/symtable.pyt   __call__   s
    !(   t   __name__t
   __module__R!   R&   R+   (    (    (    s   scripts/common/Lib/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   | |  _  | |  _ h  |  _ d  S(   N(   t   _tablet	   _filenamet   _symbols(   R    t	   raw_tableR   (    (    s   scripts/common/Lib/symtable.pyR!   +   s    		c         C   sq   |  i  t j o
 d } n d |  i  i } |  i i d j o d i | |  i ƒ Sd i | |  i i |  i ƒ Sd  S(   Nt    s   %s t   globals   <{0}SymbolTable for module {1}>s   <{0}SymbolTable for {1} in {2}>(   t	   __class__R   R,   R.   R   t   formatR/   (   R    t   kind(    (    s   scripts/common/Lib/symtable.pyt   __repr__0   s    
		c         C   s�   |  i  i t i j o d S|  i  i t i j o d S|  i  i t i j o d S|  i  i d j p t d i |  i  i ƒ ‚ 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   scripts/common/Lib/symtable.pyt   get_type=   s    c         C   s
   |  i  i S(   N(   R.   t   id(   R    (    (    s   scripts/common/Lib/symtable.pyt   get_idG   s    c         C   s
   |  i  i S(   N(   R.   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt   get_nameJ   s    c         C   s
   |  i  i S(   N(   R.   t   lineno(   R    (    (    s   scripts/common/Lib/symtable.pyt
   get_linenoM   s    c         C   s'   t  |  i i t i j o |  i i ƒ S(   N(   t   boolR.   R"   R   R#   t	   optimized(   R    (    (    s   scripts/common/Lib/symtable.pyt   is_optimizedP   s    c         C   s   t  |  i i ƒ S(   N(   RC   R.   t   nested(   R    (    (    s   scripts/common/Lib/symtable.pyt	   is_nestedT   s    c         C   s   t  |  i i ƒ S(   N(   RC   R.   t   children(   R    (    (    s   scripts/common/Lib/symtable.pyt   has_childrenW   s    c         C   s   t  |  i i t t B@ƒ S(   s"   Return true if the scope uses exec(   RC   R.   RD   R   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt   has_execZ   s    c         C   s   t  |  i i t @ƒ S(   s&   Return true if the scope uses import *(   RC   R.   RD   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt   has_import_star^   s    c         C   s   |  i  i i ƒ  S(   N(   R.   t   symbolst   keys(   R    (    (    s   scripts/common/Lib/symtable.pyt   get_identifiersb   s    c         C   sc   |  i  i | ƒ } | d  j o@ |  i i | } |  i | ƒ } t | | | ƒ } |  i  | <n | S(   N(   R0   R'   R(   R.   RL   t   _SymbolTable__check_childrenR   (   R    R   t   symt   flagst
   namespaces(    (    s   scripts/common/Lib/symtable.pyt   lookupe   s    !c         C   s.   g  } |  i  ƒ  D] } | |  i | ƒ q ~ S(   N(   RN   RS   (   R    t   _[1]t   ident(    (    s   scripts/common/Lib/symtable.pyt   get_symbolsm   s    c         C   sE   g  } |  i  i D]- } | i | j o | t | |  i ƒ q q ~ S(   N(   R.   RH   R   R   R/   (   R    R   RT   t   st(    (    s   scripts/common/Lib/symtable.pyt   __check_childrenp   s    c         C   s1   g  } |  i  i D] } | t | |  i ƒ q ~ S(   N(   R.   RH   R   R/   (   R    RT   RW   (    (    s   scripts/common/Lib/symtable.pyt   get_childrenu   s    (   R,   R-   R!   R7   R=   R?   R@   RB   RE   RG   RI   RJ   RK   RN   RS   RV   RO   RY   (    (    (    s   scripts/common/Lib/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   sF   t  g  } |  i ƒ  D]( } | |  i i | ƒ o | | q q ~ ƒ S(   N(   t   tupleRN   R.   RL   (   R    t	   test_funcRT   RU   (    (    s   scripts/common/Lib/symtable.pyt   __idents_matching‚   s    c         C   s0   |  i  d  j o |  i d „  ƒ |  _  n |  i  S(   Nc         S   s   |  t  @S(    (   R   (   t   x(    (    s   scripts/common/Lib/symtable.pyt   <lambda>ˆ   s    (   t   _Function__paramsR(   t   _Function__idents_matching(   R    (    (    s   scripts/common/Lib/symtable.pyt   get_parameters†   s    c         C   s0   |  i  d  j o |  i d „  ƒ |  _  n |  i  S(   Nc         S   s   |  t  @S(    (   R   (   R]   (    (    s   scripts/common/Lib/symtable.pyR^   �   s    (   t   _Function__localsR(   R`   (   R    (    (    s   scripts/common/Lib/symtable.pyt
   get_locals‹   s    c            sH   |  i  d  j o1 t t f ‰  ‡  f d †  } |  i | ƒ |  _  n |  i  S(   Nc            s   |  t  ?t @ˆ  j S(    (   R	   R
   (   R]   (   t   glob(    s   scripts/common/Lib/symtable.pyR^   “   s    (   t   _Function__globalsR(   R   R   R`   (   R    t   test(    (   Rd   s   scripts/common/Lib/symtable.pyt   get_globals�   s
    c         C   s6   |  i  d  j o d „  } |  i | ƒ |  _  n |  i  S(   Nc         S   s   |  t  ?t @t j S(    (   R	   R
   R   (   R]   (    (    s   scripts/common/Lib/symtable.pyR^   ™   s    (   t   _Function__freesR(   R`   (   R    t   is_free(    (    s   scripts/common/Lib/symtable.pyt	   get_frees—   s    	N(   R,   R-   R(   R_   Rb   Rh   Re   R`   Ra   Rc   Rg   Rj   (    (    (    s   scripts/common/Lib/symtable.pyR   z   s   				c           B   s   e  Z d Z d  „  Z RS(   c         C   sT   |  i  d  j o= h  } x! |  i i D] } d | | i <q# Wt | ƒ |  _  n |  i  S(   Ni   (   t   _Class__methodsR(   R.   RH   R   RZ   (   R    t   dRW   (    (    s   scripts/common/Lib/symtable.pyt   get_methods¢   s     N(   R,   R-   R(   Rk   Rm   (    (    (    s   scripts/common/Lib/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 d „  Z d „  Z d „  Z RS(   c         C   s7   | |  _  | |  _ | t ?t @|  _ | p d |  _ d  S(   N(    (   t   _Symbol__namet   _Symbol__flagsR	   R
   t   _Symbol__scopet   _Symbol__namespaces(   R    R   RQ   RR   (    (    s   scripts/common/Lib/symtable.pyR!   ­   s    		c         C   s   d i  |  i ƒ S(   Ns   <symbol {0!r}>(   R5   Rn   (   R    (    (    s   scripts/common/Lib/symtable.pyR7   ³   s    c         C   s   |  i  S(   N(   Rn   (   R    (    (    s   scripts/common/Lib/symtable.pyR@   ¶   s    c         C   s   t  |  i t i @ƒ S(   N(   RC   Ro   R   R    (   R    (    (    s   scripts/common/Lib/symtable.pyt   is_referenced¹   s    c         C   s   t  |  i t @ƒ S(   N(   RC   Ro   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt   is_parameter¼   s    c         C   s   t  |  i t t f j ƒ S(   N(   RC   Rp   R   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt	   is_global¿   s    c         C   s   t  i d t d ƒ t S(   Ns+   is_vararg() is obsolete and will be removedi   (   t   warningst   warnt   DeprecationWarningt   False(   R    (    (    s   scripts/common/Lib/symtable.pyt	   is_varargÂ   s    	
c         C   s   t  i d t d ƒ t S(   Ns/   is_keywordarg() is obsolete and will be removedi   (   Ru   Rv   Rw   Rx   (   R    (    (    s   scripts/common/Lib/symtable.pyt   is_keywordargÇ   s    	
c         C   s   t  |  i t j ƒ S(   N(   RC   Rp   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt   is_declared_globalÌ   s    c         C   s   t  |  i t @ƒ S(   N(   RC   Ro   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt   is_localÏ   s    c         C   s   t  |  i t j ƒ S(   N(   RC   Rp   R   (   R    (    (    s   scripts/common/Lib/symtable.pyRi   Ò   s    c         C   s   t  |  i t @ƒ S(   N(   RC   Ro   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt   is_importedÕ   s    c         C   s   t  |  i t @ƒ S(   N(   RC   Ro   R   (   R    (    (    s   scripts/common/Lib/symtable.pyt   is_assignedØ   s    c         C   s   t  i d t d ƒ d  S(   Ns-   is_in_tuple() is obsolete and will be removedi   (   Ru   Rv   Rw   (   R    (    (    s   scripts/common/Lib/symtable.pyt   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.
        (   RC   Rq   (   R    (    (    s   scripts/common/Lib/symtable.pyt   is_namespaceß   s    c         C   s   |  i  S(   s.   Return a list of namespaces bound to this name(   Rq   (   R    (    (    s   scripts/common/Lib/symtable.pyt   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    (   t   lenRq   t
   ValueError(   R    (    (    s   scripts/common/Lib/symtable.pyt   get_namespaceð   s    N(   R,   R-   R(   R!   R7   R@   Rr   Rs   Rt   Ry   Rz   R{   R|   Ri   R}   R~   R   R€   R�   R„   (    (    (    s   scripts/common/Lib/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   Ru   R   t   __all__R   R   R   t   objectR   R   R   R   R,   t   ost   syst   opent   argvt   readt   srct   patht   splitt   modRN   RU   RS   t   infoR|   R€   (    (    (    s   scripts/common/Lib/symtable.pyt   <module>   s(   ^		Q$N) 