source: products/quintagroup.pagetemplateshrink/trunk/quintagroup/pagetemplateshrink/__init__.py @ 1520

Last change on this file since 1520 was 1520, checked in by chervol, 14 years ago

typo fixes

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1from zope.tal.htmltalparser import HTMLTALParser
2from zope.tal.talgenerator import TALGenerator
3from zope.pagetemplate import pagetemplate
4
5import re
6expression = re.compile('[ \n\f\r]+(?=</?(?:me)?tal)')
7expression2 = re.compile('\n\s*\n+(?= *<)')
8
9def cook(self):
10    """Compile the TAL and METAL statments.
11
12    Cooking must not fail due to compilation errors in templates.
13    """
14    engine = self.pt_getEngine()
15    source_file = self.pt_source_file()
16    if self.content_type == 'text/html':
17        gen = TALGenerator(engine, xml=0, source_file=source_file)
18        parser = HTMLTALParser(gen)
19    else:
20        gen = TALGenerator(engine, source_file=source_file)
21        parser = TALParser(gen)
22
23    self._v_errors = ()
24    try:
25        #### the patch
26        text = self._text
27        text = expression.sub('', text)
28        text = expression2.sub('', text)
29        parser.parseString(text)
30        #parser.parseString(self._text)
31        self._v_program, self._v_macros = parser.getCode()
32    except:
33        self._v_errors = ["Compilation failed",
34                          "%s: %s" % sys.exc_info()[:2]]
35    self._v_warnings = parser.getWarnings()
36    self._v_cooked = 1
37
38pagetemplate.PageTemplate._old_cook = pagetemplate.PageTemplate._cook
39pagetemplate.PageTemplate._cook = cook
Note: See TracBrowser for help on using the repository browser.