Commit 00602175 authored by Guido van Rossum's avatar Guido van Rossum

Give the TALInterpreter class constructor a 'strictinsert' option,

default true.  When this is false, structure insertion without
attribute replacement does not parse the inserted text.  This is
(expected to be) much faster, but allows invalid HTML/XML to be
inserted, so it is off by default.

Evan can choose to turn this on in ZPT if he's more concerned about
efficiency than about correctness. :-)
parent d6496fcc
...@@ -150,7 +150,8 @@ class AltTALGenerator(TALGenerator): ...@@ -150,7 +150,8 @@ class AltTALGenerator(TALGenerator):
class TALInterpreter: class TALInterpreter:
def __init__(self, program, macros, engine, stream=None, def __init__(self, program, macros, engine, stream=None,
debug=0, wrap=60, metal=1, tal=1, showtal=-1): debug=0, wrap=60, metal=1, tal=1, showtal=-1,
strictinsert=1):
self.program = program self.program = program
self.macros = macros self.macros = macros
self.engine = engine self.engine = engine
...@@ -164,6 +165,7 @@ class TALInterpreter: ...@@ -164,6 +165,7 @@ class TALInterpreter:
if showtal == -1: if showtal == -1:
showtal = (not tal) showtal = (not tal)
self.showtal = showtal self.showtal = showtal
self.strictinsert = strictinsert
self.html = 0 self.html = 0
self.slots = {} self.slots = {}
self.currentMacro = None self.currentMacro = None
...@@ -321,6 +323,10 @@ class TALInterpreter: ...@@ -321,6 +323,10 @@ class TALInterpreter:
if structure is None: if structure is None:
return return
text = str(structure) text = str(structure)
if not repldict and not self.strictinsert:
# Take a shortcut, no error checking
self.stream_write(text)
return
if self.html: if self.html:
self.insertHTMLStructure(text, repldict) self.insertHTMLStructure(text, repldict)
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment