示例#1
0
 def test_disallowed_builtin(self):
     from zope.pagetemplate.engine import ZopePythonExpr
     expr = ZopePythonExpr('python', 'open("x", "w")', DummyEngine())
     self.assertRaises(NameError, expr, DummyContext())
示例#2
0
 def test_allowed_module_name(self):
     from zope.pagetemplate.engine import ZopePythonExpr
     expr = ZopePythonExpr('python', '__import__("sys").__name__',
                           DummyEngine())
     self.assertEqual(expr(DummyContext()), 'sys')
示例#3
0
 def test_forbidden_module_name(self):
     from zope.pagetemplate.engine import ZopePythonExpr
     from zope.security.interfaces import Forbidden
     expr = ZopePythonExpr('python', '__import__("sys").exit',
                           DummyEngine())
     self.assertRaises(Forbidden, expr, DummyContext())
示例#4
0
 def test_simple(self):
     from zope.pagetemplate.engine import ZopePythonExpr
     expr = ZopePythonExpr('python', 'max(a,b)', DummyEngine())
     self.assertEqual(expr(DummyContext(a=1, b=2)), 2)