Trusted expression engine.
This engine allows modules to be imported:
>>> modname = 'zope.app.pagetemplate.tests.trusted' >>> engine = _TrustedEngine() >>> context = engine.getContext(engine.getBaseNames()) >>> modname in sys.modules False >>> m = context.evaluate('modules/' + modname) >>> m.__name__ == modname True >>> modname in sys.modules True
Since this is trusted code, we can look at whatever is in the module, not just __name__ or what's declared in a security assertion:
>>> m.x 42
Clean up after ourselves:
>>> del sys.modules[modname]
There are no attributes in this class.
compile(expression)
getBaseNames()
getCompilerError()
getContext(_ZopeBaseEngine__namespace=None, **namespace)
getFunctionNamespace(namespacename)
Returns the function namespace
getTypes()
registerBaseName(name, object)
registerFunctionNamespace(namespacename, namespacecallable)
Register a function namespace
parameter:
This callable should return an object which can be traversed to get the functions provided by the this namespace.
example:
class stringFuncs(object):
- def __init__(self,context):
- self.context = str(context)
- def upper(self):
- return self.context.upper()
- def lower(self):
- return self.context.lower()
engine.registerFunctionNamespace('string',stringFuncs)
registerType(name, handler)
There are no known subclasses.