~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/zptsupport.py

  • Committer: j.c.sackett
  • Date: 2011-11-08 16:29:37 UTC
  • mto: This revision was merged to the branch mainline in revision 459.
  • Revision ID: jonathan.sackett@canonical.com-20111108162937-nq0pyhk2hracu62f
Updated NEWS with the change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import logging
19
19
import os
20
20
import pkg_resources
 
21
import re
21
22
import StringIO
22
23
 
23
24
from simpletal import simpleTAL, simpleTALES
24
25
 
25
 
logging.getLogger("simpleTAL").setLevel(logging.INFO)
26
 
logging.getLogger("simpleTALES").setLevel(logging.INFO)
27
 
 
28
 
 
29
26
_zpt_cache = {}
 
27
 
 
28
 
30
29
def zpt(tfile):
31
30
    tinstance = _zpt_cache.get(tfile)
32
31
    stat = os.stat(tfile)
33
32
    if tinstance is None or tinstance.stat != stat:
 
33
        text = open(tfile).read()
 
34
        text = re.sub(r'\s*\n\s*', '\n', text)
 
35
        text = re.sub(r'[ \t]+', ' ', text)
34
36
        tinstance = _zpt_cache[tfile] = TemplateWrapper(
35
 
            simpleTAL.compileXMLTemplate(open(tfile)), tfile, stat)
 
37
            simpleTAL.compileXMLTemplate(text), tfile, stat)
36
38
    return tinstance
37
39
 
38
40
 
74
76
        package = classname[0:divider]
75
77
        basename = classname[divider+1:]
76
78
    else:
77
 
        raise ValueError, "All templates must be in a package"
 
79
        raise ValueError("All templates must be in a package")
78
80
 
79
81
    tfile = pkg_resources.resource_filename(
80
82
        package, "%s.%s" % (basename, "pt"))