~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/zptsupport.py

  • Committer: Michael Hudson
  • Date: 2008-06-20 02:24:58 UTC
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: michael.hudson@canonical.com-20080620022458-qgpah31u1yqz9sfp
reorder imports in start-loggerhead.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# This program is free software; you can redistribute it and/or modify
3
 
# it under the terms of the GNU General Public License as published by
4
 
# the Free Software Foundation; either version 2 of the License, or
5
 
# (at your option) any later version.
6
 
#
7
 
# This program is distributed in the hope that it will be useful,
8
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
# GNU General Public License for more details.
11
 
#
12
 
# You should have received a copy of the GNU General Public License
13
 
# along with this program; if not, write to the Free Software
14
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 
#
16
1
"""Support for Zope Page Templates using the simpletal library."""
17
2
 
18
3
import logging
19
4
import os
20
5
import pkg_resources
21
 
import re
22
6
import StringIO
23
7
 
24
8
from simpletal import simpleTAL, simpleTALES
28
12
 
29
13
 
30
14
_zpt_cache = {}
31
 
 
32
 
 
33
15
def zpt(tfile):
34
16
    tinstance = _zpt_cache.get(tfile)
35
17
    stat = os.stat(tfile)
36
18
    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
19
        tinstance = _zpt_cache[tfile] = TemplateWrapper(
41
 
            simpleTAL.compileXMLTemplate(text), tfile, stat)
 
20
            simpleTAL.compileXMLTemplate(open(tfile)), tfile, stat)
42
21
    return tinstance
43
22
 
44
23
 
80
59
        package = classname[0:divider]
81
60
        basename = classname[divider+1:]
82
61
    else:
83
 
        raise ValueError("All templates must be in a package")
 
62
        raise ValueError, "All templates must be in a package"
84
63
 
85
64
    tfile = pkg_resources.resource_filename(
86
65
        package, "%s.%s" % (basename, "pt"))