[Zope-Checkins] CVS: Zope2 - RestrictionMutator.py:1.1.2.4

shane@digicool.com shane@digicool.com
Fri, 20 Apr 2001 13:24:14 -0400 (EDT)


Update of /cvs-repository/Zope2/lib/python/RestrictedPython
In directory korak:/tmp/cvs-serv20686

Modified Files:
      Tag: RestrictedPythonBranch
	RestrictionMutator.py 
Log Message:
Hack in a different way, this way works



--- Updated File RestrictionMutator.py in package Zope2 --
--- RestrictionMutator.py	2001/04/19 22:50:11	1.1.2.3
+++ RestrictionMutator.py	2001/04/20 17:24:13	1.1.2.4
@@ -184,16 +184,13 @@
     elif kind == 'eval':
         tree = Transformer().parseexpr(s)
         MutatingWalker.walk(tree, rm)
-        # XXX No "NestedScopeEvalCodeGenerator" exists
+        # XXX No "EvalCodeGenerator" exists
         # so here's a hack that gets around it.
-        gen = pycodegen.NestedScopeModuleCodeGenerator(name)
-        tree = ast.Module(None, ast.Stmt([ast.Assign([ast.AssName(
-            '__', OP_ASSIGN)], ast.Lambda((), (), 0, tree))]))
+        gen = pycodegen.ModuleCodeGenerator(name)
+        gen.emit('SET_LINENO', 0)
         visitor.walk(tree, gen)
+        gen.emit('RETURN_VALUE')
         code = gen.getCode()
-        d = {}
-        exec code in d
-        code = d['__'].func_code
     else:
         raise ValueError, 'Unsupported compile kind: ' + kind
 
@@ -285,3 +282,16 @@
     # Test: no access to builtin getattr.  getattr(guarded_ob, '_ob')
     # Test: no access to globals()
     
+
+
+if __name__ == '__main__2':
+    c1 = compile_restricted('2+2', 'sdh', 'eval')
+    c2 = compile('2+2', 'sdh', 'eval')
+    for k in dir(c1):
+        v1 = getattr(c1, k)
+        v2 = getattr(c2, k)
+        if v1 != v2:
+            print k, `v1`, `v2`
+    import dis
+    dis.dis(c1)
+    dis.dis(c2)