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

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

the patchcode added

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