Expression Compiler¶
-
class
zope.tales.tales.ExpressionEngine[source]¶ Bases:
objectExpression compiler, an implementation of
zope.tal.interfaces.ITALExpressionCompiler.An instance of this class keeps
a mutable collection of expression type handlers. It can compile expression strings by delegating to these handlers. It canprovide an expression engine, which is capable of holding state and evaluating compiled expressions.By default, this object does not know how to compile any expression types. See
zope.tales.engine.Engineandzope.tales.engine.DefaultEngine()for pre-configured instances supporting the standard expression types.-
registerFunctionNamespace(namespacename, namespacecallable)[source]¶ Register a function namespace
Parameters: - namespace (str) – a string containing the name of the namespace to be registered
- namespacecallable (callable) –
a callable object which takes the following parameter:
context: the object on which the functions provided by this namespace will be called This callable should return an object which can be traversed to get the functions provided by the this namespace.
For 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)[source]¶ Register an expression of name to be handled with handler.
Raises: RegistrationError – If this is a duplicate registration for name, or if name is not a valid expression type name.
-
getContext(contexts=None, **kwcontexts)[source]¶ Return a new expression engine.
The keyword arguments passed in kwcantexts become the default variable context for the returned engine. If contexts is given, it should be a mapping, and the values it contains will override the keyword arguments.
Return type: Context
-
-
zope.tales.engine.DefaultEngine()[source]¶ Create and return an instance of
ExpressionEngine(an implementation ofzope.tal.interfaces.ITALExpressionCompiler) with the following expression types registered:stringStringExprpythonPythonExprnotNotExprdeferDeferExprlazyLazyExprmodulesSimpleModuleImporter
In addition, the default
pathexpressions (standard,path,existsandnocall), all implemented byPathExpr, are registered.
-
zope.tales.engine.Engine¶ An instance of the default engine (
DefaultEngine()) that can be used for simple shared cases