mò *á¸Ec@s¼dZddd!ZdklZlZlZlZlZdkl Z l Z l Z l Z l Z lZlZdkZdklZd„Zd e fd „ƒYZd „Zdd „Zd d„Zd d„Zd„Zdfd„ƒYZdeeifd„ƒYZdeeifd„ƒYZdeeifd„ƒYZdeei fd„ƒYZ dee fd„ƒYZ!dee fd„ƒYZ"dee fd „ƒYZ#d!e#fd"„ƒYZ$dS(#sUCompiles restricted code using the compiler module from the Python standard library. s$Revision: 1.6 $i iþÿÿÿ(sastsparsesmiscssyntaxs pycodegen(sAbstractCompileModes Expressions InteractivesModulesModuleCodeGeneratorsFunctionCodeGeneratorsfindOpN(sRestrictionMutatorcCsOyt||ƒSWn7yt|||ƒWntj o ‚nX‚nXdS(N(tparsetsourcetmodetcompiletfilenamet SyntaxError(RRR((t8/data/zmath/zope/lib/python/RestrictedPython/RCompile.pyt niceParsestRestrictedCompileModecBs2tZdZd„Zd„Zd„Zd„ZRS(s8Abstract base class for hooking up custom CodeGenerator.cCsC|odi|iƒƒ}ntƒ|_ti|||ƒdS(Ns ( Rtjoint splitlinestRestrictionMutatortselftrmtAbstractCompileModet__init__R(R RR((RR,s cCst|i|i|iƒS(N(RR RRR(R ((RR2scCsg|iƒ}ti||iƒ|iiot|iid‚nti |i |ƒt i |ƒ|S(Ni( R RttreetMutatingWalkertwalkR terrorsRtmisct set_filenameRtsyntaxtcheck(R R((Rt _get_tree5s   cCs.|iƒ}|i|ƒ}|iƒ|_dS(N(R RRtCodeGeneratorClasstgentgetCodetcode(R RR((RR>s (t__name__t __module__t__doc__RRRR(((RR(s    cCsmy|iƒWn:tj o.}dt|ƒf|ii|iifSnX|i ƒf|ii|iifS(N( RRRtvtNonetstrR twarningst used_namesR(RR ((RtcompileAndTuplizeDs *cCs"t|||||ƒ}t|ƒS(smCompiles a restricted code object for a function. The function can be reconstituted using the 'new' module: new.function(, ) The globalize argument, if specified, is a list of variable names to be treated as globals (code is generated as if each name in the list appeared in a global statement at the top of the function). N(t RFunctiontptbodytnameRt globalizeRR%(R'R(R)RR*R((Rtcompile_restricted_functionKs scCst||ƒ}t|ƒS(s!Compiles a restricted code suite.N(tRModuletsRRR%(R-RR((Rtcompile_restricted_execYscCst||ƒ}t|ƒS(s!Compiles a restricted expression.N(t RExpressionR-RRR%(R-RR((Rtcompile_restricted_eval^scCs€|djot||ƒ}nM|djot||ƒ}n-|djot||ƒ}n tdƒ‚|iƒ|i ƒS(s/Replacement for the builtin compile() function.tsingletexectevalsAcompile_restricted() 3rd arg must be 'exec' or 'eval' or 'single'N( Rt RInteractiveRRRR,R/t ValueErrorRR(RRRR((Rtcompile_restrictedcs     tRestrictedCodeGeneratorcBs5tZdZd„Zd„ZeZeZd„ZRS(sšMixin for CodeGenerator to replace UNPACK_SEQUENCE bytecodes. The UNPACK_SEQUENCE opcode is not safe because it extracts elements from a sequence without using a safe iterator or making __getitem__ checks. This code generator replaces use of UNPACK_SEQUENCE with calls to a function that unpacks the sequence, performes the appropriate security checks, and returns a simple list. cCsA|iddƒ|idƒ|iddƒ|id|ƒdS(Nt LOAD_GLOBALt _getiter_tROT_TWOt CALL_FUNCTIONitUNPACK_SEQUENCE(R temittnum(R R>((Rt_gen_safe_unpack_sequence€s  cCsRt|ƒdjo|it|iƒƒnx|iD]}|i|ƒq7WdS(Nt OP_DELETE(tfindOptnodeR R?tlentnodestchildtvisit(R RBRE((Rt_visitAssSequenceŽs  cCsY|it|ƒƒx?|D]7}t|tƒo|i|ƒq|id|ƒqWdS(NtSTORE( R R?RCttupteltt isinstancettupletunpackSequencet_nameOp(R RIRJ((RRMšs (RRRR?RGt visitAssTuplet visitAssListRM(((RR7qs   tRestrictedFunctionCodeGeneratorcBstZRS(N(RR(((RRQ¦st!RestrictedExpressionCodeGeneratorcBstZRS(N(RR(((RRRªst"RestrictedInteractiveCodeGeneratorcBstZRS(N(RR(((RRS®stRestrictedModuleCodeGeneratorcBstZd„ZRS(NcCsti|ƒt|i_dS(N(tModuleCodeGeneratort initClassR RQt __class__t FunctionGen(R ((RRVµs (RRRV(((RRT²sR/cBstZdZeZRS(NR3(RRRRRR(((RR/ÀsR4cBstZdZeZRS(NR1(RRRRSR(((RR4ÄsR,cBstZdZeZRS(NR2(RRRRTR(((RR,ÈsR&cBs&tZdZeZd„Zd„ZRS(s.A restricted Python function built from parts.cCsb||_|odi|iƒƒ}n||_||_|pg|_ti |d|ƒdS(Ns ( R'R tparamsR(R R R)tglobalsR,RR!R(R R'R(R)RRZ((RRÑs   cCsd|i}t|ddƒ}|iid}t|i|i dƒ}|ii|i _|i |_ t |i iƒdjof|i id}t|tiƒo?t|itiƒo)t|iitƒo|ii|_qän|io&|i iidti|iƒƒn|S(Nsdef f(%s): passsR2i(R RYt firstlineRRRBRDtfR(Rt body_codeRR)RCtstmt1RKtasttDiscardtexprtConsttvalueR"tdocRZtinserttGlobal(R R[R\RR]R^((RRÚs  ? &(RRRRTRRR(((RR&Ìs  (%Rt __version__tcompilerR_RRRt pycodegentcompiler.pycodegenRt Expressiont InteractivetModuleRUtFunctionCodeGeneratorRARR RRR%R!R+R.R0R6R7RQtExpressionCodeGeneratorRRtInteractiveCodeGeneratorRSRTR/R4R,R&(RRSRRRR&RR0R,RTR6R R+R.RiRARnRR4R_RQR/R7RkRlRRRRgRmRUR%((Rt?s* %1        5