[ @sdZddlZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZddlZdddddgZd dZGd d d ZeZGd ddeZGd ddeZGdddeZGdddeZedkrddlZddlZeejdZej Z!WdQXee!ej"j#ejdddZ$xBe$j%D]1Z&e$j'e&Z(e)e(e(j*e(j+qWndS)z2Interface to the compiler's internal symbol tablesN)USE DEF_GLOBAL DEF_LOCAL DEF_PARAM DEF_IMPORT DEF_BOUNDOPT_IMPORT_STAR SCOPE_OFF SCOPE_MASKFREELOCALGLOBAL_IMPLICITGLOBAL_EXPLICITCELLsymtable SymbolTableClassFunctionSymbolcCs"tj|||}t||S)N) _symtabler_newSymbolTable)codefilenameZ compile_typetopr/usr/lib/python3.4/symtable.pyr sc@s4eZdZddZddZddZdS)SymbolTableFactorycCstj|_dS)N)weakrefWeakValueDictionary_SymbolTableFactory__memo)selfrrr__init__szSymbolTableFactory.__init__cCsK|jtjkrt||S|jtjkr>t||St||S)N)typer TYPE_FUNCTIONr TYPE_CLASSrr)r tablerrrrnews   zSymbolTableFactory.newcCsQ||f}|jj|d}|dkrM|j||}|j|z<{0}SymbolTable for {1} in {2}>) __class__rr+r.nameformatr/)r Zkindrrr__repr__,s   zSymbolTable.__repr__cCs||jjtjkrdS|jjtjkr2dS|jjtjkrKdS|jjdksxtdj|jjdS) NmoduleZfunctionclasszunexpected type: {0})r9r:r;)r.r"rZ TYPE_MODULEr#r$AssertionErrorr5)r rrrget_type9szSymbolTable.get_typecCs |jjS)N)r.id)r rrrget_idCszSymbolTable.get_idcCs |jjS)N)r.r4)r rrrget_nameFszSymbolTable.get_namecCs |jjS)N)r.lineno)r rrr get_linenoIszSymbolTable.get_linenocCs&t|jjtjko"|jj S)N)boolr.r"rr# optimized)r rrr is_optimizedLszSymbolTable.is_optimizedcCst|jjS)N)rCr.nested)r rrr is_nestedPszSymbolTable.is_nestedcCst|jjS)N)rCr.children)r rrr has_childrenSszSymbolTable.has_childrencCsdS)z7Return true if the scope uses exec. Deprecated method.Fr)r rrrhas_execVszSymbolTable.has_execcCst|jjt@S)z&Return true if the scope uses import *)rCr.rDr)r rrrhas_import_starZszSymbolTable.has_import_starcCs|jjjS)N)r.symbolskeys)r rrrget_identifiers^szSymbolTable.get_identifierscCsa|jj|}|dkr]|jj|}|j|}t|||}|j|js z+SymbolTable.get_symbols..)rN)r r)r r get_symbolsiszSymbolTable.get_symbolscs fddjjDS)Ncs1g|]'}|jkrt|jqSr)r4rr/)rSst)r4r rrrUms z0SymbolTable.__check_children..)r.rH)r r4r)r4r rZ__check_childrenlszSymbolTable.__check_childrencsfddjjDS)Ncs"g|]}t|jqSr)rr/)rSrW)r rrrUrs z,SymbolTable.get_children..)r.rH)r r)r r get_childrenqszSymbolTable.get_childrenN)r+r,r-r!r6r=r?r@rBrErGrIrJrKrNrRrVrOrXrrrrr%s              c@sdeZdZdZdZdZdZddZddZddZ dd Z d d Z dS) rNcs&tfddjDS)Ncs,g|]"}jj|r|qSr)r.rL)rSrT)r test_funcrrrUs z.Function.__idents_matching..)tuplerN)r rYr)r rYrZ__idents_matching~szFunction.__idents_matchingcCs1|jdkr*|jdd|_n|jS)NcSs|t@S)N)r)xrrrsz)Function.get_parameters..)_Function__params_Function__idents_matching)r rrrget_parametersszFunction.get_parameterscsI|jdkrBttffdd}|j||_n|jS)Ncs|t?t@kS)N)r r )r[)locsrrr\sz%Function.get_locals..)_Function__localsr rr^)r testr)r`r get_localss  zFunction.get_localscsI|jdkrBttffdd}|j||_n|jS)Ncs|t?t@kS)N)r r )r[)globrrr\sz&Function.get_globals..)_Function__globalsr rr^)r rbr)rdr get_globalss  zFunction.get_globalscCs7|jdkr0dd}|j||_n|jS)NcSs|t?t@tkS)N)r r r )r[rrrr\sz$Function.get_frees..)_Function__freesr^)r is_freerrr get_freess zFunction.get_frees) r+r,r-r]rargrer^r_rcrfrirrrrrvs     c@s"eZdZdZddZdS)rNcCsR|jdkrKi}x!|jjD]}d||j)r5rm)r rrrr6szSymbol.__repr__cCs|jS)N)rm)r rrrr@szSymbol.get_namecCst|jtj@S)N)rCrnrr)r rrr is_referencedszSymbol.is_referencedcCst|jt@S)N)rCrnr)r rrr is_parameterszSymbol.is_parametercCst|jttfkS)N)rCror r)r rrr is_globalszSymbol.is_globalcCst|jtkS)N)rCror)r rrris_declared_globalszSymbol.is_declared_globalcCst|jt@S)N)rCrnr)r rrris_localszSymbol.is_localcCst|jtkS)N)rCror )r rrrrhszSymbol.is_freecCst|jt@S)N)rCrnr)r rrr is_importedszSymbol.is_importedcCst|jt@S)N)rCrnr)r rrr is_assignedszSymbol.is_assignedcCs t|jS)aReturns 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. )rCrp)r rrr is_namespaces zSymbol.is_namespacecCs|jS)z.Return a list of namespaces bound to this name)rp)r rrrget_namespacesszSymbol.get_namespacescCs/t|jdkr$tdn|jdS)zReturns the single namespace bound to this name. Raises ValueError if the name is bound to multiple namespaces. r9z$name is bound to multiple namespacesr)lenrp ValueError)r rrr get_namespaceszSymbol.get_namespace)r+r,r-r!r6r@rqrrrsrtrurhrvrwrxryr|rrrrrs            __main__r9exec),__doc__rrrrrrrrr r r r r rrr__all__rrrobjectrrrrr+ossysopenargvfreadsrcpathsplitmodrNrTrRinfoprintrurxrrrrs& ^   Q& @ )