ofc)@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|scCsz|ddtjkstt|dkrm|ddtjkrm|j|d}|j||dS|j|S(Niii(R0ttestRnR*tcomp_forRmtcom_generator_expressionR(RGRhR((s,/usr/lib64/python2.7/compiler/transformer.pyt testlist_compHs )cCst|dkr:|ddtjkr:|j|dS|j|d}t|dkrt|dkswt|dddkst|dddkst|j|d}|j|d}t|||d |ddS|S( NiiitifitelseiiR((R*R0R\RmRntIfExp(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(RGRhteltRR_((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(RGRhR%R_((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(RGRhRRRRjR_R((s,/usr/lib64/python2.7/compiler/transformer.pyR~-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  (cCs|dtjkst|d}|j|dd}t|dkrV|dfS|dddkspt|ddtjkst||ddfS(Niitasi(R0tdotted_as_nameRnRR*RR5RD(RGR_tdot((s,/usr/lib64/python2.7/compiler/transformer.pytcom_dotted_as_namevs  cCsz|dtjkst|d}|j|dg}x:tdt|dD] }|j|j||qRW|S(Niii(R0tdotted_as_namesRnR1RR*R(RGR_RRj((s,/usr/lib64/python2.7/compiler/transformer.pyRs  cCs|dtjkst|d}|ddtjks@tt|dkrd|dddfS|dddkst||ddtjkst|dd|ddfS(NiiR.i(R0timport_as_nameRnR5RDR*R(RGR_((s,/usr/lib64/python2.7/compiler/transformer.pytcom_import_as_names  cCsz|dtjkst|d}|j|dg}x:tdt|dD] }|j|j||qRW|S(Niii(R0timport_as_namesRnR4RR*R(RGR_RRj((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(iiRtfinally( 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(RGRhR>R(tvarRT((s,/usr/lib64/python2.7/compiler/transformer.pyR=s cCs!|dtjkst|dS(Nii(R0t augassignRn(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 SubscriptRpR,R(RGR_R"((s,/usr/lib64/python2.7/compiler/transformer.pyRscCsTxM|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 |qdS( 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 assigningRtprimaryRjtch((s,/usr/lib64/python2.7/compiler/transformer.pyRsL $             cCs\g}x=tdt|dD]#}|j|j|||qWt|dt|S(NiiR((RR*RRtAssTupleR%(RGR_RMtassignsRj((s,/usr/lib64/python2.7/compiler/transformer.pyRHs!cCsg}xtdt|dD]}|dt|kr||ddtjkrbtdn||ddtjkst||dn|j|j |||qWt |dt |S(Niiis"can't assign to list comprehensionR(( RR*R0tlist_forR,R5RRnRRtAssListR%(RGR_RMRQRj((s,/usr/lib64/python2.7/compiler/transformer.pyRKs 2!cCst|d|d|dS(NiR(i(tAssName(RGR_RM((s,/usr/lib64/python2.7/compiler/transformer.pyRL%scCs|dd}|tjkr4|j||d|S|tjkrZ|j||d|S|tjkrutdntd|dS(Niiiscan't assign to function callsunknown trailer type: %s(R5Rotcom_assign_attrR:tcom_subscriptlistR8R,(RGRNR_RMR((s,/usr/lib64/python2.7/compiler/transformer.pyRJ(s cCst||d|d|dS(NiR(i(tAssAttr(RGRNR_RM((s,/usr/lib64/python2.7/compiler/transformer.pyRU2scCst|}|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    $cCsK|j||d}|dk s+tt|tr>|St|gS(Ni(RRRnR$Rg(RGR_R((s,/usr/lib64/python2.7/compiler/transformer.pyRaAs cCs^|j||d}|dk s+tt|trM|j|jn |j|dS(Ni(RRRnR$RgtextendR!R(RGRkR_R((s,/usr/lib64/python2.7/compiler/transformer.pyReHs cCsg}xtdt|D]}||dtjkrmt||dksUt|j|d||S||dtjkrqn|j|j ||qWt |d|dj S(NiiR(( RR*R0RRRntcom_list_comprehensionR5RRRmRR((RGRhtvaluesRj((s,/usr/lib64/python2.7/compiler/transformer.pyR Ps  cCs|j|d|dS(NRL(tcom_comprehensionR(RGRTR_((s,/usr/lib64/python2.7/compiler/transformer.pyRZ]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(NiitforiiRLRR(is'unexpected comprehension element: %s %dtsettdictsunexpected comprehension type: (RRRmt ListCompForR(RR*Rt com_list_itert com_comp_itert ListCompIftifsR,tListComptSetComptDictCompRtrepr( RGRRR_RR(tforsRRtcompNodetnewforRtnewif((s,/usr/lib64/python2.7/compiler/transformer.pyR\`sD            cCs!|dtjkst|dS(Nii(R0t list_iterRn(RGR_((s,/usr/lib64/python2.7/compiler/transformer.pyRascCs!|dtjkst|dS(Nii(R0t comp_iterRn(RGR_((s,/usr/lib64/python2.7/compiler/transformer.pyRbsc 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( NiiR]iR(iRis.unexpected generator expression element: %s %di(RRRmt GenExprForRR*RRbt GenExprIfRdR,tTruet is_outmosttGenExprt GenExprInner( RGRTR_R(RiRRtgenNodeRkRRl((s,/usr/lib64/python2.7/compiler/transformer.pyRs2       c Cs|dtjkst|d}t|dksL|ddtjkrg}x:tdt|dD] }|j|j||qkWt |d|dj S|ddtj kr|j|d}|j |d|ddSt|dkrp|ddtj krp|ddtjks0t|j|d}|j|d}|j |||ddSg}xQtdt|dD]7}|j|j|||j||dfqWt|d|ddj SdS( NiiiR(R^iR_i(R0tdictorsetmakerRnR*R5RRRRmtSetR(RR\RRR"(RGRhR2RjRTtkeyRH((s,/usr/lib64/python2.7/compiler/transformer.pyR#s( ))cCs|dd}|tjkr1|j||dS|tjkrT|j||dS|tjkrz|j||dtStd|dS(Niiisunknown node type: %s( R5R8RuRotcom_select_memberR:RVRR,(RGt primaryNodeRhR((s,/usr/lib64/python2.7/compiler/transformer.pyRscCs:|dtjkrtdnt||dd|dS(Nismember must be a nameiR(i(R5RDR,Rp(RGRzRh((s,/usr/lib64/python2.7/compiler/transformer.pyRys 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$RsR0RR( RGRzRhR,tkwt star_nodet dstar_nodet len_nodelistRjR_R((s,/usr/lib64/python2.7/compiler/transformer.pyRus:         )  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(RGRhR}R~RRR`R_((s,/usr/lib64/python2.7/compiler/transformer.pyR|s")   (c Cst|dkr|d}|ddtjks\t|dkr|ddtjkr|ddtjkr|j|||Sng}x:tdt|dD] }|j|j||qWt |||dt |S(NiiiiR(( R*R5RR0Rt com_sliceRRt com_subscriptRER%(RGRNRhRMtsubt subscriptsRj((s,/usr/lib64/python2.7/compiler/transformer.pyRV"s )cCs||d}|d}|tjkrA|ddtjkrAtS|tjksbt|dkro|j|S|j|S(Niii(R5RotEllipsisRR*t com_sliceobjRm(RGR_ROR((s,/usr/lib64/python2.7/compiler/transformer.pyR6s  &! 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_R2RjtjRO((s,/usr/lib64/python2.7/compiler/transformer.pyR@s  )  cCsd}}t|dkr_|ddtjkrI|j|d}q|j|d}n;t|dkr|j|d}|j|d}nt||||dt|S(NiiiiiR((RR*R5RRmRDR%(RGRNR_RMtlowertupper((s,/usr/lib64/python2.7/compiler/transformer.pyRds 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`RtsR((s,/usr/lib64/python2.7/compiler/transformer.pyRcrs8      N(RRt__doc__RJRQRRRWRORYRZR[RrRwRzR|R]R\t old_lambdefR^RRt flow_stmtt compound_stmtRRR}RRRtRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRGt testlist1RFRRRtold_testRRRRTRRRR RRRRR7R9R;R=R?R)RARCRRmR4R~R+R-RR1RR4RRRRR=RRRRHRKRLRJRURRaReR RZR\RaRbRR#RRyRuR|RVRRRRRc(((s,/usr/lib64/python2.7/compiler/transformer.pyR^s          !                                         !                2      )  ,       1   "   '   $ ts==s<=s>=s!=RRcCsxg}xk|D]c}t|tr>|jtj||q t|tr]|j|q |jt|q W|S(N(R$tintRt_namestgetR+t debug_tree(RPR"R((s,/usr/lib64/python2.7/compiler/transformer.pyRs (SRt compiler.astRMR0R5t StandardErrorRtcompiler.constsRRRRRRR RR%R.RRRRGRRRRRRTRRRR RRRRtLESStGREATERtEQEQUALRt LESSEQUALt GREATEREQUALtNOTEQUALRR]R^RRRRRRRRRRRRRRRRRRRRRRRRFRt_legal_node_typesRRRRRIRR1R2R%tvttok_nameR(((s,/usr/lib64/python2.7/compiler/transformer.pyt s      9