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]

TAL interpreter.

Some notes on source annotations. They are HTML/XML comments added to the output whenever sourceFile is changed by a setSourceFile bytecode. Source annotations are disabled by default, but you can turn them on by passing a sourceAnnotations 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:

  1. setPosition bytecode follows setSourceFile, and we need position information to output the line number.
  2. 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:

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).
class zope.tal.talinterpreter.FasterStringIO(value=None)[source]

Bases: list

write()

L.append(object) – append object to end