diff --git a/CHANGES b/CHANGES index eb3853499dbde667495ef05bd16db16d89c1d824..7f7d0a94a25a6810f48fe516f6deb5e84f4ac4be 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,11 @@ drive etc.) and no URI - the URI is converted to a forward-slash path and module_directory is treated as a windows path. [ticket:128] + +- TemplateLookup raises TopLevelLookupException for + a given path that is a directory, not a filename, + instead of passing through to the template to + generate IOError. [ticket:73] 0.2.6 diff --git a/mako/lookup.py b/mako/lookup.py index 0398c5e91ace11334508271734df8bda804f3556..8514a8a6e0e76a0aa5ac673ea53b62e657457e01 100644 --- a/mako/lookup.py +++ b/mako/lookup.py @@ -107,7 +107,7 @@ class TemplateLookup(TemplateCollection): u = re.sub(r'^\/+', '', uri) for dir in self.directories: srcfile = posixpath.normpath(posixpath.join(dir, u)) - if os.path.exists(srcfile): + if os.path.isfile(srcfile): return self._load(srcfile, uri) else: raise exceptions.TopLevelLookupException( diff --git a/test/test_lookup.py b/test/test_lookup.py index 4d6644d2645e9e632ca1316af923015432b6ee63..5e6cb24137eaefeecc4c339bbb9bbfec42ae9be0 100644 --- a/test/test_lookup.py +++ b/test/test_lookup.py @@ -29,6 +29,13 @@ class LookupTest(unittest.TestCase): "this is include 2" ] + + def test_directory_lookup(self): + """test that hitting an existent directory still raises LookupError.""" + + self.assertRaises(exceptions.TopLevelLookupException, + tl.get_template, "/subdir" + ) def test_no_lookup(self): t = Template("hi <%include file='foo.html'/>")