Commit a52cd58e authored by Florent Guillaume's avatar Florent Guillaume

Provide an opportunity for third-party products to use a full

Unicode-aware StringIO by monkey-patching two appropriate methods
until one is completely integrated into Zope.
parent 13a7c0e2
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
HTML- and XML-based template objects using TAL, TALES, and METAL. HTML- and XML-based template objects using TAL, TALES, and METAL.
""" """
__version__='$Revision: 1.25 $'[11:-2] __version__='$Revision: 1.26 $'[11:-2]
import sys import sys
...@@ -43,6 +43,11 @@ class PageTemplate(Base): ...@@ -43,6 +43,11 @@ class PageTemplate(Base):
_text = '' _text = ''
_error_start = '<!-- Page Template Diagnostics' _error_start = '<!-- Page Template Diagnostics'
def StringIO(self):
# Third-party products wishing to provide a full Unicode-aware
# StringIO can do so by monkey-patching this method.
return StringIO()
def macros(self): def macros(self):
return self.pt_macros() return self.pt_macros()
macros = ComputedAttribute(macros, 1) macros = ComputedAttribute(macros, 1)
...@@ -80,7 +85,7 @@ class PageTemplate(Base): ...@@ -80,7 +85,7 @@ class PageTemplate(Base):
if self._v_errors: if self._v_errors:
raise PTRuntimeError, 'Page Template %s has errors.' % self.id raise PTRuntimeError, 'Page Template %s has errors.' % self.id
output = StringIO() output = self.StringIO()
c = self.pt_getContext() c = self.pt_getContext()
c.update(extra_context) c.update(extra_context)
......
...@@ -114,6 +114,11 @@ class TALInterpreter: ...@@ -114,6 +114,11 @@ class TALInterpreter:
self.scopeLevel = 0 self.scopeLevel = 0
self.sourceFile = None self.sourceFile = None
def StringIO(self):
# Third-party products wishing to provide a full Unicode-aware
# StringIO can do so by monkey-patching this method.
return StringIO()
def saveState(self): def saveState(self):
return (self.position, self.col, self.stream, return (self.position, self.col, self.stream,
self.scopeLevel, self.level) self.scopeLevel, self.level)
...@@ -319,7 +324,7 @@ class TALInterpreter: ...@@ -319,7 +324,7 @@ class TALInterpreter:
def no_tag(self, start, program): def no_tag(self, start, program):
state = self.saveState() state = self.saveState()
self.stream = stream = StringIO() self.stream = stream = self.StringIO()
self._stream_write = stream.write self._stream_write = stream.write
self.interpret(start) self.interpret(start)
self.restoreOutputState(state) self.restoreOutputState(state)
...@@ -565,7 +570,7 @@ class TALInterpreter: ...@@ -565,7 +570,7 @@ class TALInterpreter:
def do_onError_tal(self, (block, handler)): def do_onError_tal(self, (block, handler)):
state = self.saveState() state = self.saveState()
self.stream = stream = StringIO() self.stream = stream = self.StringIO()
self._stream_write = stream.write self._stream_write = stream.write
try: try:
self.interpret(block) self.interpret(block)
......
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