³ò ¢l‡Jc @sÇdZddkZddkZddkTddklZddddgeZ[dd „Zdd „Zdd „Z ddddd „Z e Z d „Z d„Z d„Zedjo eƒndS(s0Disassembler of Python byte code into mnemonics.iÿÿÿÿN(t*(t__all__tdist disassembletdistbtdiscocCs{|djotƒdSnt|ƒtijo |i}nt|dƒo |i}nt|dƒo |i}nt|dƒoœ|i i ƒ}|i ƒxÒ|D]t\}}t|ƒti ti titifjo=d|GHyt|ƒWntj o}dG|GHnXHq©q©WnSt|dƒot|ƒn5t|tƒot|ƒntdt|ƒi‚dS( 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(tNoneRttypettypest InstanceTypet __class__thasattrRRRtitemstsortt MethodTypet FunctionTypetCodeTypet ClassTypeRt TypeErrorRt isinstancetstrtdisassemble_stringt__name__(txRtnametx1tmsg((s/sys/lib/python/dis.pyR s>        cCsr|djoKy ti}Wntj otd‚nXx|io |i}q<Wnt|ii|i ƒdS(s2Disassemble a traceback (default: last traceback).s no last traceback to disassembleN( R tsystlast_tracebacktAttributeErrort RuntimeErrorttb_nextRttb_frametf_codettb_lasti(ttb((s/sys/lib/python/dis.pyR2s  c Cs}|i}t|ƒ}tt|ƒƒ}t|ƒ}d}d}d}x1||jo#||} t| ƒ} ||jo"|djoHnd||GndG||jodGndG||jodGndGt|ƒidƒGt | i dƒG|d }| t joht||ƒt||d ƒd |} d}|d }| t jo| d }nt| ƒid ƒG| t jodt|i| ƒdGqs| tjod|i| dGqs| tjodt|| ƒdGqs| tjod|i| dGqs| tjodt| dGqs| tjo5|djo|i|i}nd|| dGqsnHqHWdS(sDisassemble a code object.is%3ds s-->s>>s iiiiilit(t)s(to N(R t findlabelstdicttfindlinestartstlenR tordtreprtrjusttopnametljustt HAVE_ARGUMENTt EXTENDED_ARGthasconstt co_conststhasnametco_namesthasjrelthaslocalt co_varnamest hascomparetcmp_opthasfreet co_cellvarst co_freevars( tcotlastitcodetlabelst linestartstntit extended_argtfreetctoptoparg((s/sys/lib/python/dis.pyR<sX         *         c Csòt|ƒ}t|ƒ}d}xÍ||jo¿||}t|ƒ} ||jodGndG||jodGndGt|ƒidƒGt| idƒG|d}| tjo7t||ƒt||dƒd } |d }t| ƒid ƒG| tjo-|od t|| ƒd Gqäd| Gqè| t jo-|dj od || d Gqäd| Gqè| t jodt|| ƒd Gqè| t jo'|od || d Gqäd| Gqè| t jod t| d GqènHq!WdS(Nis-->s s>>s iiiiiiR(R)s(%d)s(to (R*R-R.R/R0R1R2R3R5R7R R9R:R<R=( RCRBtvarnamestnamest constantsRDRFRGRJRKRL((s/sys/lib/python/dis.pyRmsD      &          cCsùg}t|ƒ}d}xÚ||joÌ||}t|ƒ}|d}|tjo›t||ƒt||dƒd}|d}d}|tjo||}n|tjo |}n|djo"||jo|i|ƒqìqðqqW|S(s`Detect all offsets in a byte code which are jump targets. Return the list of offsets. iiiiiÿÿÿÿ(R-R.R3R9thasjabstappend(RCRDRFRGRJRKRLtlabel((s/sys/lib/python/dis.pyR*—s&     &      c csg}|iddd…D]}|t|ƒq~}g}|iddd…D]}|t|ƒqR~}d}|i}d}x^t||ƒD]M\} } | o0||jo||fV|}n|| 7}n|| 7}q“W||jo||fVndS(s”Find 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( RCt_[1]RJtbyte_incrementst_[2]tline_incrementst lastlinenotlinenotaddrt byte_incrt line_incr((s/sys/lib/python/dis.pyR,±s77      cCsætido_tido!tiidƒtidƒntid}| p |djo d}qsnd}|djo ti}n t|ƒ}|iƒ}|dj o|i ƒnd}t ||dƒ}t |ƒdS(s*Simple test program to disassemble a file.iisusage: python dis.py [-|file] t-stexecN( RtargvtstderrtwritetexitR tstdintopentreadtclosetcompileR(tfntftsourceRC((s/sys/lib/python/dis.pyt_testÇs"      t__main__(t__doc__RR topcodeRt _opcodes_allR RRRRRR*R,RmR(((s/sys/lib/python/dis.pyss"    & 1  '