Interfaces

Interface that a TAL expression implementation provides to the METAL/TAL implementation.

This package does not provide an implementation of ITALExpressionCompiler, ITALExpressionEngine or ITALIterator. An external package must provide those. The most commonly used are zope.tales.tales.ExpressionEngine, zope.tales.tales.Context, and zope.tales.tales.Iterator, respectively.

interface zope.tal.interfaces.ITALExpressionCompiler[source]

Compile-time interface provided by a TAL expression implementation.

The TAL compiler needs an instance of this interface to support compilation of TAL expressions embedded in documents containing TAL and METAL constructs.

getCompilerError()

Return the exception class raised for compilation errors.

compile(expression)

Return a compiled form of expression for later evaluation.

expression is the source text of the expression.

The return value may be passed to the various evaluate*() methods of the ITALExpressionEngine interface. No compatibility is required for the values of the compiled expression between different ITALExpressionEngine implementations.

getContext(namespace)

Create an expression execution context

The given namespace provides the initial top-level names.

interface zope.tal.interfaces.ITALExpressionEngine[source]

Render-time interface provided by a TAL expression implementation.

The TAL interpreter uses this interface to TAL expression to support evaluation of the compiled expressions returned by ITALExpressionCompiler.compile().

getDefault()

Return the value of the default TAL expression.

Checking a value for a match with default should be done using the is operator in Python.

setPosition(position)

Inform the engine of the current position in the source file.

position is a tuple (lineno, offset).

This is used to allow the evaluation engine to report execution errors so that site developers can more easily locate the offending expression.

setSourceFile(filename)

Inform the engine of the name of the current source file.

This is used to allow the evaluation engine to report execution errors so that site developers can more easily locate the offending expression.

beginScope()

Push a new scope onto the stack of open scopes.

endScope()

Pop one scope from the stack of open scopes.

evaluate(compiled_expression)

Evaluate an arbitrary expression.

No constraints are imposed on the return value.

evaluateBoolean(compiled_expression)

Evaluate an expression that must return a Boolean value.

evaluateMacro(compiled_expression)

Evaluate an expression that must return a macro program.

evaluateStructure(compiled_expression)

Evaluate an expression that must return a structured document fragment.

The result of evaluating compiled_expression must be a string containing a parsable HTML or XML fragment. Any TAL markup contained in the result string will be interpreted.

evaluateText(compiled_expression)

Evaluate an expression that must return text.

The returned text should be suitable for direct inclusion in the output: any HTML or XML escaping or quoting is the responsibility of the expression itself.

If the expression evaluates to None, then that is returned. It represents nothing in TALES. If the expression evaluates to what getDefault() returns, by comparison using is, then that is returned. It represents default in TALES.

evaluateValue(compiled_expression)

Evaluate an arbitrary expression.

No constraints are imposed on the return value.

createErrorInfo(exception, position)

Returns an ITALExpressionErrorInfo object.

position is a tuple (lineno, offset).

The returned object is used to provide information about the error condition for the on-error handler.

setGlobal(name, value)

Set a global variable.

The variable will be named name and have the value value.

setLocal(name, value)

Set a local variable in the current scope.

The variable will be named name and have the value value.

getValue(name, default=None)

Get a variable by name.

If the variable does not exist, return default.

setRepeat(name, compiled_expression)

Start a repetition, returning an ITALIterator.

The engine is expected to add the a value (typically the returned iterator) for the name to the variable namespace.

translate(msgid, domain=None, mapping=None, default=None)

See zope.i18n.interfaces.ITranslationDomain.translate

evaluateCode(lang, code)

Evaluates code of the given language.

Returns whatever the code outputs. This can be defined on a per-language basis. In Python this usually everything the print statement will return.

interface zope.tal.interfaces.ITALIterator[source]

A TAL iterator

Not to be confused with a Python iterator.

next()

Advance to the next value in the iteration, if possible

Return a true value if it was possible to advance and return a false value otherwise.

interface zope.tal.interfaces.ITALExpressionErrorInfo[source]

Information about an error.

type

The exception class.

value

The exception instance.

lineno

The line number the error occurred on in the source.

offset

The character offset at which the error occurred.