On Unix, when calling get_template using a path which implies a valid
file is a directory, an IOError is uncaught, rather than a
TemplateDoesNotExist being raised, which would be my expectation, and
which is the behaviour on Windows.
For example:
>>> environment.get_template("www/index.html")
<Template 'www/index.html'>
>>> environment.get_template("www/index.html/index.html")
IOError Traceback (most recent call
last)
/home/custuser/<ipython console> in <module>()
/usr/local/lib/python2.5/site-packages/Jinja2-2.5-py2.5.egg/jinja2/
environment.pyc in get_template(self, name, parent, globals)
714 if parent is not None:
715 name = self.join_path(name, parent)
--> 716 return self._load_template(name,
self.make_globals(globals))
717
718 @internalcode
/usr/local/lib/python2.5/site-packages/Jinja2-2.5-py2.5.egg/jinja2/
environment.pyc in _load_template(self, name, globals)
688
template.is_up_to_date):
689 return template
--> 690 template = self.loader.load(self, name, globals)
691 if self.cache is not None:
692 self.cache[name] = template
/usr/local/lib/python2.5/site-packages/Jinja2-2.5-py2.5.egg/jinja2/
loaders.pyc in load(self, environment, name, globals)
113 # first we try to get the source for this template
together
114 # with the filename and the uptodate function.
--> 115 source, filename, uptodate =
self.get_source(environment, name)
116
117 # try to load the code from the bytecode cache if
there is a
/usr/local/lib/python2.5/site-packages/Jinja2-2.5-py2.5.egg/jinja2/
loaders.pyc in get_source(self, environment, template)
373 for loader in self.loaders:
374 try:
--> 375 return loader.get_source(environment,
template)
376 except TemplateNotFound:
377 pass
/usr/local/lib/python2.5/site-packages/Jinja2-2.5-py2.5.egg/jinja2/
loaders.pyc in get_source(self, environment, template)
163 for searchpath in self.searchpath:
164 filename = path.join(searchpath, *pieces)
--> 165 f = open_if_exists(filename)
166 if f is None:
167 continue
/usr/local/lib/python2.5/site-packages/Jinja2-2.5-py2.5.egg/jinja2/
utils.py in open_if_exists(filename, mode)
222 """
223 try:
--> 224 return open(filename, mode)
225 except IOError, e:
226 if e.errno not in (errno.ENOENT, errno.EISDIR):
IOError: [Errno 20] Not a directory: '/data/prod/nu/content/sites/
aviva/templates/www/index.html/index.html'
I would suggest catching the case of errno.ENOTDIR along with ENOENT
and EISDIR above, as in the below patch, unless there is some reason
against.
diff -r 978e52f40de3 jinja2/utils.py
--- a/jinja2/utils.py Tue Jul 06 12:00:33 2010 +0200
+++ b/jinja2/utils.py Mon Jul 12 14:25:49 2010 +0100
@@ -223,7 +223,7 @@
try:
return open(filename, mode)
except IOError, e:
- if e.errno not in (errno.ENOENT, errno.EISDIR):
+ if e.errno not in (errno.ENOENT, errno.EISDIR,
errno.ENOTDIR):
raise
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.