mò *á¸Ec@sbdZdkZdkZd„Zd„Zd„Zdefd„ƒYZdd„Zd „Z dS( s¹Verify simple properties of bytecode. Some of the transformations performed by the RestrictionMutator are tricky. This module checks the generated bytecode as a way to verify the correctness of the transformations. Violations of some restrictions are obvious from inspection of the bytecode. For example, the bytecode should never contain a LOAD_ATTR call, because all attribute access is performed via the _getattr_() checker function. NcCsCt|ƒx2|iD]'}t|tiƒot|ƒqqWdS(s†Verify all code objects reachable from code. In particular, traverse into contained code objects in the co_consts table. N(t verifycodetcodet co_conststobt isinstancettypestCodeTypetverify(RR((t</data/zmath/zope/lib/python/RestrictedPython/tests/verify.pyRs   cCs,yt|ƒWnti|ƒ‚nXdS(N(t _verifycodeRtdis(R((RR&s  cCs|i}d}xt|ƒD]ú}|idj o |i}n|iidƒoe|i djo%|didjo|didjp)t d|i|i t i |fƒ‚q·n|idjo|did jo%|d id jo|d i d jpMx-t |ƒD]\}}|G|iG|i GHqWt d|i |fƒ‚qTn|iidƒoq|did jo9|didjo%|d id jo|d i djpt d|i |fƒ‚qØn|idjot d|i |fƒ‚n|f|d }qWdS(Nt LOAD_ATTRtappenditDUP_TOPit BUILD_LISTs%direct attribute access %s: %s, %s:%dt STORE_ATTRtDEL_ATTRt CALL_FUNCTIONit LOAD_GLOBALt_write_s"unguard attribute set/del at %s:%dtUNPACKtROT_TWOt _getiter_s"unguarded unpack sequence at %s:%dt LOAD_SUBSCRs$unguarded index of sequence at %s:%d(NNN(s STORE_ATTRR(Rtco_firstlinenotlinetNonetwindowt disassembletoptopnametendswithtargt ValueErrortcot co_filenamet enumeratetit startswith(RR%RRR((RR -s*   8-< !P!tOpcBstZdZd„ZRS( NRtargcodeR RttargettposcCs8ti||_d|_d|_t|_||_ dS(N( R RtopcodetselfRR RtFalseR)R*(R,R+R*((Rt__init__gs    (sopnameR(sargslinestargetspos(t__name__t __module__t __slots__R.(((RR']s iÿÿÿÿc cs$|i}ti|ƒ}tt|ƒƒ} t |ƒ}d}d}|i |i} xË||jo½t||ƒ} t| |ƒ}|d7}|| jo|djo| ||_n||jo t|_n| tijo7t||ƒt||dƒd|}d}|d7}| tijo|d>}n||_| tijo|i||_q| tijo|i||_q| tijo|||_q| ti jo|i!||_q| ti"joti#||_q| ti$jo| ||_qn|VqUWdS(Niiiii(%R"tco_codeRR t findlabelstlabelstdicttfindlinestartst linestartstlentnR%t extended_argt co_cellvarst co_freevarstfreetordRR'toRtTrueR)t HAVE_ARGUMENTR t EXTENDED_ARGR(thasconstRthasnametco_namesthasjrelthaslocalt co_varnamest hascomparetcmp_opthasfree( R"tlastiR?R:RR%R R4R9R=RR7((RRnsH      *  c csg}|iddd…D]}|t|ƒq~}g}|iddd…D]}|t|ƒqR~}d}|i }d}x]t ||ƒD]L\} }| o/||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_[1]Rt co_lnotabtcR>tbyte_incrementstline_incrementsRt lastlinenoRtlinenotaddrtzipt byte_incrt line_incr( RRORTRMRQRWRSRPRRRV((RR6–s 77      ( t__doc__R RRRR tobjectR'RR6(RR RRR6R RR'((Rt?s    0 (