Commit 3e71cd77 authored by Fred Drake's avatar Fred Drake

another spurious difference avoided between Zopes:

use the pushStream/popStream model from the Zope 3 codebase instead of the
interpretWithStream model.  The two are entirely equivalent in context,
but I think the push/pop model offers more flexibility in the long run
parent 7385f6c8
...@@ -160,8 +160,8 @@ class TALInterpreter: ...@@ -160,8 +160,8 @@ class TALInterpreter:
self.macros = macros self.macros = macros
self.engine = engine # Execution engine (aka context) self.engine = engine # Execution engine (aka context)
self.Default = engine.getDefault() self.Default = engine.getDefault()
self.stream = stream or sys.stdout self._stream_stack = [stream or sys.stdout]
self._stream_write = self.stream.write self.popStream()
self.debug = debug self.debug = debug
self.wrap = wrap self.wrap = wrap
self.metal = metal self.metal = metal
...@@ -195,12 +195,12 @@ class TALInterpreter: ...@@ -195,12 +195,12 @@ class TALInterpreter:
return FasterStringIO() return FasterStringIO()
def saveState(self): def saveState(self):
return (self.position, self.col, self.stream, return (self.position, self.col, self.stream, self._stream_stack,
self.scopeLevel, self.level, self.i18nContext) self.scopeLevel, self.level, self.i18nContext)
def restoreState(self, state): def restoreState(self, state):
(self.position, self.col, self.stream, (self.position, self.col, self.stream,
scopeLevel, level, i18n) = state self._stream_stack, scopeLevel, level, i18n) = state
self._stream_write = self.stream.write self._stream_write = self.stream.write
assert self.level == level assert self.level == level
while self.scopeLevel > scopeLevel: while self.scopeLevel > scopeLevel:
...@@ -211,7 +211,7 @@ class TALInterpreter: ...@@ -211,7 +211,7 @@ class TALInterpreter:
def restoreOutputState(self, state): def restoreOutputState(self, state):
(dummy, self.col, self.stream, (dummy, self.col, self.stream,
scopeLevel, level, i18n) = state self._stream_stack, scopeLevel, level, i18n) = state
self._stream_write = self.stream.write self._stream_write = self.stream.write
assert self.level == level assert self.level == level
assert self.scopeLevel == scopeLevel assert self.scopeLevel == scopeLevel
...@@ -237,15 +237,14 @@ class TALInterpreter: ...@@ -237,15 +237,14 @@ class TALInterpreter:
self._stream_write("\n") self._stream_write("\n")
self.col = 0 self.col = 0
def interpretWithStream(self, program, stream): def pushStream(self, newstream):
oldstream = self.stream self._stream_stack.append(self.stream)
self.stream = stream self.stream = newstream
self._stream_write = stream.write self._stream_write = self.stream.write
try:
self.interpret(program) def popStream(self):
finally: self.stream = self._stream_stack.pop()
self.stream = oldstream self._stream_write = self.stream.write
self._stream_write = oldstream.write
def stream_write(self, s, def stream_write(self, s,
len=len): len=len):
...@@ -549,7 +548,11 @@ class TALInterpreter: ...@@ -549,7 +548,11 @@ class TALInterpreter:
state = self.saveState() state = self.saveState()
try: try:
tmpstream = self.StringIO() tmpstream = self.StringIO()
self.interpretWithStream(program, tmpstream) self.pushStream(tmpstream)
try:
self.interpret(program)
finally:
self.popStream()
if self.html and self._currentTag == "pre": if self.html and self._currentTag == "pre":
value = tmpstream.getvalue() value = tmpstream.getvalue()
else: else:
...@@ -601,7 +604,11 @@ class TALInterpreter: ...@@ -601,7 +604,11 @@ class TALInterpreter:
# subnodes, which should /not/ go to the output stream. # subnodes, which should /not/ go to the output stream.
currentTag = self._currentTag currentTag = self._currentTag
tmpstream = self.StringIO() tmpstream = self.StringIO()
self.interpretWithStream(stuff[1], tmpstream) self.pushStream(tmpstream)
try:
self.interpret(stuff[1])
finally:
self.popStream()
# We only care about the evaluated contents if we need an implicit # We only care about the evaluated contents if we need an implicit
# message id. All other useful information will be in the i18ndict on # message id. All other useful information will be in the i18ndict on
# the top of the i18nStack. # the top of the i18nStack.
......
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