{fc)@sfdZddlTddlZddlZddlZdefdYZddlmZm Z ddlm Z m Z m Z dZ d d Zd Zd Zd ZdfdYZejejejejejejejejejejejejejej ej!ej"gZ#idej$6dej%6dej&6dej'6dej(6dej)6dej*6Z+ej,ej-ej.ej/ej0ej1ej2ejej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejejejejejejejDejejejejejej ej!ej"ejEg)ZFeGedreFjHejIneGedreFjHejJnejejejejejejejejejejej ej!g ZKiZLx'ejMjND]\ZOZPePeLeO AST parseFile(path) -> AST i(t*Nt WalkerErrorcBseZRS((t__name__t __module__(((s,/usr/lib64/python2.7/compiler/transformer.pyR!s(t CO_VARARGStCO_VARKEYWORDS(t OP_ASSIGNt OP_DELETEtOP_APPLYcCs3t|d}|jd}|jt|S(NtUs (topentreadtclosetparse(tpathtftsrc((s,/usr/lib64/python2.7/compiler/transformer.pyt parseFile's texeccCsT|dks|dkr(tj|S|dkrDtj|StddS(NRtsingletevals4compile() arg 3 must be 'exec' or 'eval' or 'single'(t Transformert parsesuitet parseexprt ValueError(tbuftmode((s,/usr/lib64/python2.7/compiler/transformer.pyR 1s  cCsg}x|D]}t|dr8|j|jq t|tdkrl|jtt|q t|tgkr|jt|q |j|q W|S(NtasList(NN(thasattrtappendRttypetNonettuple(tnodestltitem((s,/usr/lib64/python2.7/compiler/transformer.pyR:s cCsbt|dts|dSx@|dD]4}t|tr&t|}|dk rZ|Sq&q&WdS(Nii(t isinstanceR t extractLineNoR(tasttchildtlineno((s,/usr/lib64/python2.7/compiler/transformer.pyR%Hs  cGst|d}|tkr]yt||dSWqptk rYt|Gt|G|GHqpXntdt|dS(Niis$Can't find appropriate Node type: %s(R!t TypeErrortlenRtstr(targstkind((s,/usr/lib64/python2.7/compiler/transformer.pytNodeRs    RcBsUeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZeZdZdZeZeZeZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3d.Z4d/Z5d0Z6d1Z7d2Z8d3Z9e9Z:e9Z;e9Z<d4Z=d5Z>d6Z?e?Z@d7ZAd8ZBd9ZCd:ZDd;ZEd<ZFd=ZGd>ZHd?ZId@ZJdAZKdBZLdCZMdDZNdEZOdFZPdGZQdHZRdIZSdJZTdKZUdLZVdMZWdNZXdOZYdPZZdQZ[dRZ\dSZ]dTZ^dUZ_dVZ`dWZadXZbdYZcdZZdd[Zed\Zfd]Zgd^Zhd_Zid`ZjdaZkdbZldcZmddZndeZodfZpdgZqdhZrdiZsdjZtdkZudlZvdmZwdnZxdoZydpZzdqZ{drZ|dsZ}dudtZRS(vsUtility object for transforming Python parse trees. Exposes the following methods: tree = transform(ast_tree) tree = parsesuite(text) tree = parseexpr(text) tree = parsefile(fileob | filename) cCsi|_xEtjjD]4\}}t||rt|||j|scCs]t|dkrP|ddtjkrP|j|d}|j||dS|j|S(Niii(R*R0tcomp_forRmtcom_generator_expressionR(RGRhttest((s,/usr/lib64/python2.7/compiler/transformer.pyt testlist_compHs)cCst|dkr:|ddtjkr:|j|dS|j|d}t|dkr|j|d}|j|d}t|||d|ddS|S(NiiiiR((R*R0R\RmtIfExp(RGRhtthenRtelse_((s,/usr/lib64/python2.7/compiler/transformer.pyRPs)cCsJt|dkr:|ddtjkr:|j|dS|jt|S(Nii(R*R0R\RtOr(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pytor_test^s)cCs|jt|S(N(RtAnd(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pytand_testescCsA|j|d}t|dkr=t|d|ddS|S(NiiR(i(RmR*tNot(RGRhtresult((s,/usr/lib64/python2.7/compiler/transformer.pytnot_testisc Cs |j|d}t|dkr)|Sg}xtdt|dD]}||d}|d}|dtjkr|d}t|dkr|dkrd}qd}qnt|d}|dd}|j||j||fqHWt||d|S( Niiiitnotsnot insis notR((RmR*RR5RDt _cmp_typesRtCompare( RGRhR_tresultsRjtnlR`RR(((s,/usr/lib64/python2.7/compiler/transformer.pyt comparisonps"     $cCs|jt|S(N(RtBitor(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pyRTscCs|jt|S(N(RtBitxor(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pytxor_exprscCs|jt|S(N(RtBitand(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pytand_exprscCs|j|d}xtdt|dD]}|j||}||ddtjkrt||gd|dd}q,||ddtjkrt||gd|dd}q,td||ddq,W|S(NiiiR(sunexpected token: %s( RmRR*R5t LEFTSHIFTt LeftShiftRt RightShiftR(RGRhR_Rjtright((s,/usr/lib64/python2.7/compiler/transformer.pyt shift_exprs##cCs|j|d}xtdt|dD]}|j||}||ddtjkrt||gd|dd}q,||ddtjkrt||gd|dd}q,td||ddq,W|S(NiiiR(sunexpected token: %s( RmRR*R5tPLUStAddtMINUStSubR(RGRhR_RjR((s,/usr/lib64/python2.7/compiler/transformer.pyt arith_exprs##cCs |j|d}xtdt|dD]}|j||}||dd}|tjkr{t||g}ny|tjkrt||g}nU|tjkrt ||g}n1|tj krt ||g}n t d||dd|_ q,W|S(Niiisunexpected token: %s(RmRR*R5RtMultSLASHtDivtPERCENTtModt DOUBLESLASHtFloorDivRR((RGRhR_RjRtt((s,/usr/lib64/python2.7/compiler/transformer.pytterms cCs|d}|d}|j|d|dd}|tjkrXt|d|dS|tjkr{t|d|dS|tjkrt|d|d}n|S(NiiiR(i(RR5RtUnaryAddRtUnarySubtTILDEtInvert(RGRhteltR R_((s,/usr/lib64/python2.7/compiler/transformer.pytfactors  !cCs|j|d}xwtdt|D]`}||}|dtjkrwt||j||dgd|dS|j||}q)W|S(NiiR(i(RmRR*R5t DOUBLESTARtPowertcom_apply_trailer(RGRhR_RjR((s,/usr/lib64/python2.7/compiler/transformer.pytpowers   cCs|j|dd|S(Ni(RE(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pytatomscCs@|ddtjkr/tdd|ddS|j|dS(NiiR(i((R5RRRm(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pyR7scCs@|ddtjkr/tdd|ddS|j|dS(NiiR(i((R5tRSQBtListtcom_list_constructor(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pyR9scCs@|ddtjkr/tdd|ddS|j|dS(NiiR(i((R5tRBRACEtDicttcom_dictorsetmaker(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pyR;scCst|j|dS(Ni(t BackquoteRm(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pyR=scCs,t|dd}t|d|ddS(NiiR(i(RR(RGRhtk((s,/usr/lib64/python2.7/compiler/transformer.pyR?scCs[|jrM|jdkr6t|dj|j}ntd|j|fSt|SdS(Nsutf-8s iso-8859-1s# coding: %s %s(sutf-8s iso-8859-1(RFtunicodetencodeR(RGtlit((s,/usr/lib64/python2.7/compiler/transformer.pytdecode_literals  cCsFd}x%|D]}||j|d7}q Wt|d|ddS(NRUiR(ii(R"R(RGRhRR_((s,/usr/lib64/python2.7/compiler/transformer.pyRAs cCs t|ddd|ddS(NiiR(i(tName(RGRh((s,/usr/lib64/python2.7/compiler/transformer.pyRC scCs|j|dS(Ni(R/(RGR_((s,/usr/lib64/python2.7/compiler/transformer.pyRscCs|j|d|dS(Nii(R/(RGR_((s,/usr/lib64/python2.7/compiler/transformer.pyRm scGsttdS(N(RRR(RGR,((s,/usr/lib64/python2.7/compiler/transformer.pyR4'scCsg}g}d}d}x|t|kr||}|dtjks]|dtjkr+|dtjkr||d}|dtjkr|j|d|tB}|d}qn|t|kr'||d}|tjkr||d}n td||j|d|tB}nPn|j|j ||d}|t|kr||dtj kr|j|j ||d|d}nt|rt dn|d}qW|||fS(Niiisunexpected token: %sis-non-default argument follows default argument( R*R5RRRDRRRRt com_fpdefRRmt SyntaxError(RGRhR|R}R~RjR_R ((s,/usr/lib64/python2.7/compiler/transformer.pyRz-s< &    )   cCs4|ddtjkr(|j|dS|ddS(Niii(R5R8t com_fplist(RGR_((s,/usr/lib64/python2.7/compiler/transformer.pyR$_scCspt|dkr#|j|dSg}x:tdt|dD] }|j|j||qBWt|S(Nii(R*R$RRR (RGR_RLRj((s,/usr/lib64/python2.7/compiler/transformer.pyR&es cCs\d}xK|D]C}t|tdkr |ddkr ||dd}q q W|d S(NRUiiRi((R(RGR_RIR`((s,/usr/lib64/python2.7/compiler/transformer.pyRns  (cCsO|d}|j|dd}t|dkr=|dfS||ddfS(Niii(RR*R(RGR_tdot((s,/usr/lib64/python2.7/compiler/transformer.pytcom_dotted_as_namevs   cCsa|d}|j|dg}x:tdt|dD] }|j|j||q9W|S(Niii(R(RR*R(RGR_R|Rj((s,/usr/lib64/python2.7/compiler/transformer.pyRs  cCsH|d}t|dkr.|dddfS|dd|ddfS(Niii(R*R(RGR_((s,/usr/lib64/python2.7/compiler/transformer.pytcom_import_as_names cCsa|d}|j|dg}x:tdt|dD] }|j|j||q9W|S(Niii(R)RR*R(RGR_R|Rj((s,/usr/lib64/python2.7/compiler/transformer.pyRs  cCsGg}x:tdt|dD] }|j|j||qW|S(Nii(RR*RRm(RGR_RRj((s,/usr/lib64/python2.7/compiler/transformer.pyRsc Cs|ddtjkrLt|j|d|j|dd|ddSg}d}d}x4tdt|dD]}||}|dtjkr't|dkr|j|d}t|dkr|j |dt }qd}n d}}|j |||j||dfn|dtjkrw|ddkrd|j||d}q|dd kr|j||d}qqwqwWt |j|d||d|dd} |rt| |d|ddS| SdS( NiiiiR(iitelsetfinally( R5RDt TryFinallyRmRRR*R0t except_clauseRRRt TryExcept( RGRhtclausesRt finallyNodeRjR_RRt try_except((s,/usr/lib64/python2.7/compiler/transformer.pyRs6   *!cCsu|j|d}x[tt|dddD]=}|j||||dd}|dkrg|S|}q0WdS(Niiiiii(RmRR*t com_with_item(RGRhtbodyRjtret((s,/usr/lib64/python2.7/compiler/transformer.pyRs #! cCsZt|dkr+|j|dt}nd}|j|d}t|||d|S(NiiiR((R*RRRRmtWith(RGRhR3R(tvarRT((s,/usr/lib64/python2.7/compiler/transformer.pyR2s cCs|dS(Ni((RGR_((s,/usr/lib64/python2.7/compiler/transformer.pyRscCsE|j|}|jttttfkr.|Std|jjdS(sReturn node suitable for lvalue of augmented assignment Names, slices, and attributes are the only allowable nodes. scan't assign to %sN(Rmt __class__R#tSlicet SubscriptRnR%R(RGR_R"((s,/usr/lib64/python2.7/compiler/transformer.pyRscCsUxN|d}|tjtjtjtjfkr`t|dkrS|j||S|d}q|tkrt|dkrtdn|d}q|tj krq|ddtj krtdnt|dkrd|j |d}x\t dt|dD]A}||}|dt jkr7tdn|j||}qW|j||d|S|d}q|tj kr@|dd}|t jkr|d}|dt jkr=tdq=qM|t jkr|d}|dt jkrtdn|j||S|t jkr4|j|d|Stdqtd |qWdS( Niiiscan't assign to operatoriscan't assign to ()scan't assign to []scan't assign to literalsbad assignment (%s)(R0texprlistRt testlist_safeRR*tcom_assign_tuplet _assign_typesR%RRRmRR5RRtcom_assign_trailerR8RR:Rtcom_assign_listRDtcom_assign_name(RGR_t assigningR tprimaryRjtch((s,/usr/lib64/python2.7/compiler/transformer.pyRsL $             cCs\g}x=tdt|dD]#}|j|j|||qWt|dt|S(NiiR((RR*RRtAssTupleR%(RGR_RAtassignsRj((s,/usr/lib64/python2.7/compiler/transformer.pyR<s!cCsg}x}tdt|dD]c}|dt|kre||ddtjkretdqen|j|j|||qWt|dt|S(Niiis"can't assign to list comprehensionR(( RR*R0tlist_forR%RRtAssListR%(RGR_RARERj((s,/usr/lib64/python2.7/compiler/transformer.pyR?s !cCst|d|d|dS(NiR(i(tAssName(RGR_RA((s,/usr/lib64/python2.7/compiler/transformer.pyR@%scCs|dd}|tjkr4|j||d|S|tjkrZ|j||d|S|tjkrutdntd|dS(Niiiscan't assign to function callsunknown trailer type: %s(R5tDOTtcom_assign_attrR:tcom_subscriptlistR8R%(RGRBR_RAR ((s,/usr/lib64/python2.7/compiler/transformer.pyR>(s cCst||d|d|dS(NiR(i(tAssAttr(RGRBR_RA((s,/usr/lib64/python2.7/compiler/transformer.pyRJ2scCst|}|dkr9|d}|j||dSg}xDtd|dD]0}||}|j|j||dqRW||dt|S(s=Compile 'NODE (OP NODE)*' into (type, [ node1, ..., nodeN ]).iiiR((R*RRRR%(RGt constructorRhR"R`R2Rj((s,/usr/lib64/python2.7/compiler/transformer.pyR5s    $cCs9|j||d}t|tr,|St|gS(Ni(RR$Rg(RGR_R((s,/usr/lib64/python2.7/compiler/transformer.pyRaAscCsL|j||d}t|tr;|j|jn |j|dS(Ni(RR$RgtextendR!R(RGRkR_R((s,/usr/lib64/python2.7/compiler/transformer.pyReHscCsg}xtdt|D]l}||dtjkrQ|j|d||S||dtjkrnqn|j|j||qWt |d|dj S(NiiR(( RR*R0RFtcom_list_comprehensionR5RRRmRR((RGRhtvaluesRj((s,/usr/lib64/python2.7/compiler/transformer.pyRPs  cCs|j|d|dS(NRL(tcom_comprehensionR(RGRTR_((s,/usr/lib64/python2.7/compiler/transformer.pyRO]sc Cs|dd}g}x|r|dd}|dkr|j|dt}|j|d} t|| g} |dd| _|j| t|dkrd}q|dkr|j|d}q|j |d}q|dkr|j|d} t | d|dd} | j j| t|d krGd}q|dkri|j|d }q|j |d }qt d ||fqW|dkrt ||d|S|d krt||d|S|d krt|||d|Std t|dS(NiitforiiRLtifR(is'unexpected comprehension element: %s %dtsettdictsunexpected comprehension type: (RRRmt ListCompForR(RR*Rt com_list_itert com_comp_itert ListCompIftifsR%tListComptSetComptDictCompRtrepr( RGRRR_RR(tforsR RtcompNodetnewforRtnewif((s,/usr/lib64/python2.7/compiler/transformer.pyRQ`sD            cCs|dS(Ni((RGR_((s,/usr/lib64/python2.7/compiler/transformer.pyRWscCs|dS(Ni((RGR_((s,/usr/lib64/python2.7/compiler/transformer.pyRXsc Csu|dd}g}x8|rN|dd}|dkr|j|dt}|j|d}t||gd|dd}|j|t|dkrd}qK|j|d}q|dkr8|j|d} t| d|dd} |j j| t|dkr"d}qK|j|d}qt d ||fqWt |d _ t t||d|S( NiiRRiR(iRSis.unexpected generator expression element: %s %di(RRRmt GenExprForRR*RRXt GenExprIfRZR%tTruet is_outmosttGenExprt GenExprInner( RGRTR_R(R_R RtgenNodeRaRRb((s,/usr/lib64/python2.7/compiler/transformer.pyRs2       cCs|d}t|dks3|ddtjkrg}x:tdt|dD] }|j|j||qRWt|d|djS|ddtj kr|j|d}|j |d|ddSt|dkr:|ddtj kr:|j|d}|j|d}|j |||ddSg}xQtdt|dD]7}|j|j|||j||dfqYWt |d|ddjSdS( NiiiR(RTiRUi( R*R5RRRRmtSetR(R0RRQRR(RGRhR2RjRTtkeyRH((s,/usr/lib64/python2.7/compiler/transformer.pyRs$ ))cCs|dd}|tjkr1|j||dS|tjkrT|j||dS|tjkrz|j||dtStd|dS(Niiisunknown node type: %s( R5R8RqRItcom_select_memberR:RKRR%(RGt primaryNodeRhR ((s,/usr/lib64/python2.7/compiler/transformer.pyRscCs:|dtjkrtdnt||dd|dS(Nismember must be a nameiR(i(R5RDR%Rn(RGRmRh((s,/usr/lib64/python2.7/compiler/transformer.pyRls c Cs|dtjkr,t|gdt|Sg}d}d}}t|}d}x@||kr||} | dtjkr|dk rtdn|j||d}|d}qWnR| dtj kr|dk rtdn|j||d}|d}qWn|j | ||\}} |dkr|t | t r|t| dkr|| ddt jkr|tdn|j| |d}qWWt||||dt|S( NiR(is$already have the varargs indentifieris#already have the kwargs indentifieris&generator expression needs parenthesis(R5RtCallFuncR%RR*RR%RmRt com_argumentR$RgR0RR( RGRmRhR,tkwt star_nodet dstar_nodet len_nodelistRjR_R((s,/usr/lib64/python2.7/compiler/transformer.pyRqs:         )  cCsDt|dkrV|ddtjkrV|j|d}d|j||dfSt|dkr|rztdn|rtdnd|j|dfS|j|d}|d}x3t|dkr|dtjkr|d}qW|dtjkrtd|dnt|d|d|d}d|fS( Niiiis!non-keyword arg after keyword args+only named arguments may follow *expressions#keyword can't be an expression (%s)R(( R*R0RRmRR%R5RDtKeyword(RGRhRpRqRRR`R_((s,/usr/lib64/python2.7/compiler/transformer.pyRos")   (cCst|dkr|d}|ddtjks\t|dkr|ddtjkr|ddtjkr|j|||Sng}x:tdt|dD] }|j|j||qWt |||dt |S(NiiiiR(( R*R5RR0Rt com_sliceRRt com_subscriptR9R%(RGRBRhRAtsubt subscriptsRj((s,/usr/lib64/python2.7/compiler/transformer.pyRK"s )cCs||d}|d}|tjkrA|ddtjkrAtS|tjksbt|dkro|j|S|j|S(Niii(R5RItEllipsisRR*t com_sliceobjRm(RGR_RCR ((s,/usr/lib64/python2.7/compiler/transformer.pyRv6s  &! cCs>g}|ddtjkr9|jtdd}n |j|j|dd}|t|kr||dtjkr|j|j|||d}n|jtdxit |t|D]R}||}t|dkr |jtdq|j|j|dqWt |dt |S(NiiiiR(( R5RRRRRmR*R0RRtSliceobjR%(RGR_R2RjtjRC((s,/usr/lib64/python2.7/compiler/transformer.pyRz@s  )  cCsd}}t|dkr_|ddtjkrI|j|d}q|j|d}n;t|dkr|j|d}|j|d}nt||||dt|S(NiiiiiR((RR*R5RRmR8R%(RGRBR_RAtlowertupper((s,/usr/lib64/python2.7/compiler/transformer.pyRuds cCs|dkr#|d}|d}n|tjkrt|dkrU|j|dSx.|D]&}|dtjkr\|j|Sq\WdS|tjkrx.|D]&}|dtjkr|j|SqWdS|tjkr'|ddtj kr#d}x"|D]}|t |d}qW|SdS|tjksT|tj ksT|tj kre|j|dS|t krt|dkr|j|dSdS(NiiRU(RR0RRR*RcRRZRR5RBRRt small_stmtt _doc_nodes(RGR_R`RwtsR ((s,/usr/lib64/python2.7/compiler/transformer.pyRcrs8      N(RRt__doc__RJRQRRRWRORYRZR[RpRsRvRxR]R\t old_lambdefR^RRt flow_stmtt compound_stmtRRRyRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR;t testlist1R:RRRtold_testRRRRTRRRRR RRRR7R9R;R=R?R"RARCRRmR4RzR$R&RR(RR)RRRRR2RRRR<R?R@R>RJRRaReRRORQRWRXRRRRlRqRoRKRvRzRuRRc(((s,/usr/lib64/python2.7/compiler/transformer.pyR^s          !                                         !                2      )  ,       1   "   '   $ ts==s<=s>=s!=RRcCs~g}xq|D]i}t|ttfrD|jtj||q t|trc|j|q |jt|q W|S(N(R$tinttlongRt_namestgetR+t debug_tree(RPR"R((s,/usr/lib64/python2.7/compiler/transformer.pyRs (SRt compiler.astRMR0R5t StandardErrorRtcompiler.constsRRRRRRR RR%R.RRRR;RRRRRRTRRRRR RRRtLESStGREATERtEQEQUALRt LESSEQUALt GREATEREQUALtNOTEQUALRR]R^RRRRRRRRRRRRRRRRRRRRRRRR:Rt_legal_node_typesRRRRR=RR1R2Rtvttok_nameR(((s,/usr/lib64/python2.7/compiler/transformer.pyt s      9