aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mako/lookup.py18
-rw-r--r--mako/util.py5
-rw-r--r--test/test_lookup.py11
3 files changed, 25 insertions, 9 deletions
diff --git a/mako/lookup.py b/mako/lookup.py
index 7450700..d3763d6 100644
--- a/mako/lookup.py
+++ b/mako/lookup.py
@@ -287,16 +287,20 @@ class TemplateLookup(TemplateCollection):
def _check(self, uri, template):
if template.filename is None:
return template
- if not os.path.exists(template.filename):
+
+ try:
+ template_stat = os.stat(template.filename)
+ if template.module._modified_time < \
+ template_stat[stat.ST_MTIME]:
+ self._collection.pop(uri, None)
+ return self._load(template.filename, uri)
+ else:
+ return template
+ except OSError:
self._collection.pop(uri, None)
raise exceptions.TemplateLookupException(
"Cant locate template for uri %r" % uri)
- elif template.module._modified_time < \
- os.stat(template.filename)[stat.ST_MTIME]:
- self._collection.pop(uri, None)
- return self._load(template.filename, uri)
- else:
- return template
+
def put_string(self, uri, text):
"""Place a new :class:`.Template` object into this
diff --git a/mako/util.py b/mako/util.py
index 23a3277..3613a5b 100644
--- a/mako/util.py
+++ b/mako/util.py
@@ -21,6 +21,7 @@ else:
from StringIO import StringIO
import codecs, re, weakref, os, time, operator
+import collections
try:
import threading
@@ -114,7 +115,7 @@ class FastEncodingBuffer(object):
but doesnt crash on unicode data like cStringIO."""
def __init__(self, encoding=None, errors='strict', unicode=False):
- self.data = []
+ self.data = collections.deque()
self.encoding = encoding
if unicode:
self.delim = u''
@@ -125,7 +126,7 @@ class FastEncodingBuffer(object):
self.write = self.data.append
def truncate(self):
- self.data =[]
+ self.data =collections.deque()
def getvalue(self):
if self.encoding:
diff --git a/test/test_lookup.py b/test/test_lookup.py
index cfbb085..190d8a5 100644
--- a/test/test_lookup.py
+++ b/test/test_lookup.py
@@ -63,3 +63,14 @@ class LookupTest(unittest.TestCase):
tl._uri_cache[('foo', 'bar')] = '/some/path'
assert tl._uri_cache[('foo', 'bar')] == '/some/path'
+ def test_check_not_found(self):
+ tl = lookup.TemplateLookup()
+ tl.put_string("foo", "this is a template")
+ f = tl.get_template("foo")
+ assert f.uri in tl._collection
+ f.filename = "nonexistent"
+ self.assertRaises(exceptions.TemplateLookupException,
+ tl.get_template, "foo"
+ )
+ assert f.uri not in tl._collection
+