Interpreting Compiled Code¶
Interpreter for a pre-compiled TAL program.
-
class
zope.tal.talinterpreter.
MacroStackItem
[source]¶ Bases:
list
Stack entry for the TALInterpreter.macroStack.
This offers convenience attributes for more readable access.
-
class
zope.tal.talinterpreter.
TALInterpreter
(program, macros, engine, stream=None, debug=0, wrap=1023, metal=1, tal=1, showtal=-1, strictinsert=1, stackLimit=100, i18nInterpolate=1, sourceAnnotations=0)[source]¶ Bases:
object
TAL interpreter.
Some notes on source annotations. They are HTML/XML comments added to the output whenever
sourceFile
is changed by asetSourceFile
bytecode. Source annotations are disabled by default, but you can turn them on by passing asourceAnnotations
argument to the constructor. You can change the format of the annotations by overriding formatSourceAnnotation in a subclass.The output of the annotation is delayed until some actual text is output for two reasons:
setPosition
bytecode followssetSourceFile
, and we need position information to output the line number.- Comments are not allowed in XML documents before the
<?xml?>
declaration.
For performance reasons (TODO: premature optimization?) instead of checking the value of
_pending_source_annotation
on every write to the output stream, the_stream_write
attribute is changed to point to_annotated_stream_write
method whenever_pending_source_annotation
is set to True, and to _stream.write when it is False. The following invariant always holds:if self._pending_source_annotation: assert self._stream_write is self._annotated_stream_write else: assert self._stream_write is self.stream.write
Create a TAL interpreter.
Parameters: - program – A compiled program, as generated
by
zope.tal.talgenerator.TALGenerator
- macros – Namespace of macros, usually also from
TALGenerator
Optional arguments:
Parameters: - stream – output stream (defaults to sys.stdout).
- debug (bool) – enable debugging output to sys.stderr (off by default).
- wrap (int) – try to wrap attributes on opening tags to this number of column (default: 1023).
- metal (bool) – enable METAL macro processing (on by default).
- tal (bool) – enable TAL processing (on by default).
- showtal (int) – do not strip away TAL directives. A special value of -1 (which is the default setting) enables showtal when TAL processing is disabled, and disables showtal when TAL processing is enabled. Note that you must use 0, 1, or -1; true boolean values are not supported (for historical reasons).
- strictinsert (bool) – enable TAL processing and stricter HTML/XML checking on text produced by structure inserts (on by default). Note that Zope turns this value off by default.
- stackLimit (int) – set macro nesting limit (default: 100).
- i18nInterpolate (bool) – enable i18n translations (default: on).
- sourceAnnotations (bool) – enable source annotations with HTML comments (default: off).