[Checkins] SVN: Sandbox/malthe/chameleon.html/ Invalidate templates when .xss-files are modified (mtime).
Malthe Borch
mborch at gmail.com
Wed Oct 1 15:20:40 EDT 2008
Log message for revision 91650:
Invalidate templates when .xss-files are modified (mtime).
Changed:
U Sandbox/malthe/chameleon.html/CHANGES.txt
U Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
U Sandbox/malthe/chameleon.html/src/chameleon/html/template.py
-=-
Modified: Sandbox/malthe/chameleon.html/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.html/CHANGES.txt 2008-10-01 19:19:58 UTC (rev 91649)
+++ Sandbox/malthe/chameleon.html/CHANGES.txt 2008-10-01 19:20:39 UTC (rev 91650)
@@ -4,6 +4,8 @@
Head
~~~~
+- Template is invalidated when XSS-files are modified. [malthe]
+
- Added resource rebase support. [malthe]
Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/language.py 2008-10-01 19:19:58 UTC (rev 91649)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/language.py 2008-10-01 19:20:39 UTC (rev 91650)
@@ -187,6 +187,7 @@
# parse the body at initialization to fill the slots and
# attributes lists
+ self.file_dependencies = []
self.parse(file(filename).read())
def parse(self, body):
@@ -211,6 +212,9 @@
raise ValueError(
"File not found: %s" % repr(href))
+ # add to file dependencies
+ self.file_dependencies.append(filename)
+
# parse and apply rules
rules = parse_xss(filename)
for rule in rules:
@@ -259,5 +263,5 @@
element.insert(index, comment)
comment.attrib['{http://namespaces.repoze.org/xss}rebase'] = 'true'
comment.text = text
-
+
return root, doctype
Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/template.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/template.py 2008-10-01 19:19:58 UTC (rev 91649)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/template.py 2008-10-01 19:20:39 UTC (rev 91650)
@@ -1,5 +1,6 @@
from chameleon.core import template
+import os
import language
class DynamicHTMLFile(template.TemplateFile):
@@ -11,3 +12,16 @@
def render(self, content={}, attributes={}, **kwargs):
return template.TemplateFile.render(
self, content=content, attributes=attributes, **kwargs)
+
+ def mtime(self):
+ """Return the most recent modification times from the template
+ file itself and any XSS-files included."""
+
+ filenames = [self.filename]
+ filenames.extend(self.parser.file_dependencies)
+
+ try:
+ return max(map(os.path.getmtime, filenames))
+ except (IOError, OSError):
+ return 0
+
More information about the Checkins
mailing list