^Rc@sdZddlZddlZddlTddlmZddddd d geZ[ejejejej e fZ dd Z dd Zdd ZdddddZeZdZdZdZedkrendS(s0Disassembler of Python byte code into mnemonics.iN(t*(t__all__tdist disassembletdistbtdiscotfindlinestartst findlabelscCsH|dkrtdSt|tjr5|j}nt|drP|j}nt|drk|j}nt|dr|j j }|j x|D]U\}}t|t rd|GHyt |Wntk r}dG|GHnXHqqWnNt|drt|n2t|tr.t|ntdt|jdS( snDisassemble classes, methods, functions, or code. With no argument, disassemble the last traceback. Ntim_funct func_codet__dict__sDisassembly of %s:sSorry:tco_codes(don't know how to disassemble %s objects(tNoneRt isinstancettypest InstanceTypet __class__thasattrRR R titemstsortt _have_codeRt TypeErrorRtstrtdisassemble_stringttypet__name__(txRtnametx1tmsg((s/usr/lib/python2.7/dis.pyRs6          cCsl|dkrRy tj}Wntk r5tdnXx|jrN|j}q9Wnt|jj|j dS(s2Disassemble a traceback (default: last traceback).s no last traceback to disassembleN( R tsystlast_tracebacktAttributeErrort RuntimeErrorttb_nextRttb_frametf_codettb_lasti(ttb((s/usr/lib/python2.7/dis.pyR3s     c Csa|j}t|}tt|}t|}d}d}d}x||kr\||} t| } ||kr|dkrHnd||GndG||krdGndG||krdGndGt|jdGt | j dG|d }| t krXt||t||d d |} d}|d }| t krT| d }nt| jd G| t krdt|j| dGqX| tkrd|j| dGqX| tkrdt|| dGqX| tkrd|j| dGqX| tkrdt| dGqX| tkrX|dkrB|j|j}nd|| dGqXnHqHWdS(sDisassemble a code object.is%3ds s-->s>>s iiiiilit(t)s(to N(R RtdictRtlenR tordtreprtrjusttopnametljustt HAVE_ARGUMENTt EXTENDED_ARGthasconstt co_conststhasnametco_namesthasjrelthaslocalt co_varnamest hascomparetcmp_opthasfreet co_cellvarst co_freevars( tcotlastitcodetlabelst linestartstntit extended_argtfreetctoptoparg((s/usr/lib/python2.7/dis.pyR=s\           *          c Cst|}t|}d}x||kr||}t|} ||krVdGndG||krmdGndGt|jdGt| jdG|d}| tkrt||t||dd } |d }t| jd G| tkr$|rd t|| d Gqd| Gq| t krZ|dk rOd || d Gqd| Gq| t krdt|| d Gq| t kr|rd || d Gqd| Gq| t krd t| d GqnHq!WdS(Nis-->s s>>s iiiiiiR'R(s(%d)s(to (RR*R+R,R-R.R/R0R2R4R R6R7R9R:( R@R?tvarnamestnamest constantsRARCRDRGRHRI((s/usr/lib/python2.7/dis.pyRnsH        &          cCsg}t|}d}x||kr||}t|}|d}|tkrt||t||dd}|d}d}|tkr||}n|tkr|}n|dkr||kr|j|qqqqW|S(s`Detect all offsets in a byte code which are jump targets. Return the list of offsets. iiiii(R*R+R0R6thasjabstappend(R@RARCRDRGRHRItlabel((s/usr/lib/python2.7/dis.pyRs&     &       c csg|jdddD]}t|^q}g|jdddD]}t|^qF}d}|j}d}xZt||D]I\}}|r||kr||fV|}n||7}n||7}qW||kr||fVndS(sFind the offsets in a byte code which are start of lines in the source. Generate pairs (offset, lineno) as described in Python/compile.c. iNii(t co_lnotabR+R tco_firstlinenotzip( R@RGtbyte_incrementstline_incrementst lastlinenotlinenotaddrt byte_incrt line_incr((s/usr/lib/python2.7/dis.pyRs//      cCstjdrftjdr:tjjdtjdntjd}| sZ|dkrld}qlnd}|dkrtj}n t|}|j}|dk r|j nd}t ||d}t |dS(s*Simple test program to disassemble a file.iisusage: python dis.py [-|file] t-stexecN( RtargvtstderrtwritetexitR tstdintopentreadtclosetcompileR(tfntftsourceR@((s/usr/lib/python2.7/dis.pyt_tests"          t__main__(t__doc__RRtopcodeRt _opcodes_allt MethodTypet FunctionTypetCodeTypet ClassTypeRRR RRRRRRRRhR(((s/usr/lib/python2.7/dis.pyts(     # 1  '