~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/zptsupport.py

  • Committer: Tim Penhey
  • Date: 2008-08-01 04:42:14 UTC
  • mto: This revision was merged to the branch mainline in revision 190.
  • Revision ID: tim.penhey@canonical.com-20080801044214-9vtocnww36dnddne
Extend serve-branches to serve user dirs.

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
22
21
import StringIO
23
22
 
24
23
from simpletal import simpleTAL, simpleTALES
28
27
 
29
28
 
30
29
_zpt_cache = {}
31
 
 
32
 
 
33
30
def zpt(tfile):
34
31
    tinstance = _zpt_cache.get(tfile)
35
32
    stat = os.stat(tfile)
36
33
    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)
40
34
        tinstance = _zpt_cache[tfile] = TemplateWrapper(
41
 
            simpleTAL.compileXMLTemplate(text), tfile, stat)
 
35
            simpleTAL.compileXMLTemplate(open(tfile)), tfile, stat)
42
36
    return tinstance
43
37
 
44
38
 
80
74
        package = classname[0:divider]
81
75
        basename = classname[divider+1:]
82
76
    else:
83
 
        raise ValueError("All templates must be in a package")
 
77
        raise ValueError, "All templates must be in a package"
84
78
 
85
79
    tfile = pkg_resources.resource_filename(
86
80
        package, "%s.%s" % (basename, "pt"))