~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/zptsupport.py

  • Committer: Huw Wilkins
  • Date: 2011-02-15 06:36:34 UTC
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: huw.wilkins@canonical.com-20110215063634-ypjpybj716u43qed
Styled to look like Launchpad. Cleaned up CSS.

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
27
28
 
28
29
 
29
30
_zpt_cache = {}
 
31
 
 
32
 
30
33
def zpt(tfile):
31
34
    tinstance = _zpt_cache.get(tfile)
32
35
    stat = os.stat(tfile)
33
36
    if tinstance is None or tinstance.stat != stat:
 
37
        text = open(tfile).read()
 
38
        text = re.sub(r'\s*\n\s*', '\n', text)
 
39
        text = re.sub(r'[ \t]+', ' ', text)
34
40
        tinstance = _zpt_cache[tfile] = TemplateWrapper(
35
 
            simpleTAL.compileXMLTemplate(open(tfile)), tfile, stat)
 
41
            simpleTAL.compileXMLTemplate(text), tfile, stat)
36
42
    return tinstance
37
43
 
38
44
 
74
80
        package = classname[0:divider]
75
81
        basename = classname[divider+1:]
76
82
    else:
77
 
        raise ValueError, "All templates must be in a package"
 
83
        raise ValueError("All templates must be in a package")
78
84
 
79
85
    tfile = pkg_resources.resource_filename(
80
86
        package, "%s.%s" % (basename, "pt"))