Commit 82379258 authored by Evan Simpson's avatar Evan Simpson

Don't cache macro errors, and cook even if text hasn't changed.

parent 8bf40628
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,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.10 $'[11:-2] __version__='$Revision: 1.11 $'[11:-2]
import os, sys, traceback, pprint import os, sys, traceback, pprint
from TAL.TALParser import TALParser from TAL.TALParser import TALParser
...@@ -119,8 +119,7 @@ class PageTemplate: ...@@ -119,8 +119,7 @@ class PageTemplate:
self.content_type = str(content_type) self.content_type = str(content_type)
if hasattr(text, 'read'): if hasattr(text, 'read'):
text = text.read() text = text.read()
if self._text <> text: self.write(text)
self.write(text)
def pt_getContext(self): def pt_getContext(self):
c = {'template': self, c = {'template': self,
...@@ -169,7 +168,8 @@ class PageTemplate: ...@@ -169,7 +168,8 @@ class PageTemplate:
errend = find(text, '-->') errend = find(text, '-->')
if errend >= 0: if errend >= 0:
text = text[errend + 4:] text = text[errend + 4:]
self._text = text if self._text != text:
self._text = text
self._cook() self._cook()
def read(self): def read(self):
...@@ -179,17 +179,13 @@ class PageTemplate: ...@@ -179,17 +179,13 @@ class PageTemplate:
try: try:
return self.pt_render(source=1) return self.pt_render(source=1)
except: except:
tb = traceback.extract_tb(sys.exc_info()[2]) return ('%s\n Macro expansion failed\n %s\n-->\n%s' %
tb.reverse() (self._error_start, "%s: %s" % sys.exc_info()[:2],
self._v_errors = ["Macro expansion failed", self._text) )
"%s: %s" % sys.exc_info()[:2],
] + map(str, tb)
if self.html(): return ('%s\n %s\n-->\n%s' % (self._error_start,
return ('%s\n %s\n-->\n%s' % (self._error_start, join(self._v_errors, '\n '),
join(self._v_errors, '\n '), self._text))
self._text))
return self._text
def _cook(self): def _cook(self):
"""Compile the TAL and METAL statments. """Compile the TAL and METAL statments.
......
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