Skip to content
Myr

Merge pull request #1081 from pallets/open-if-exists

Before adoption: this commit came in with the history the project adopted, so no landing records it.

skip template with same name as directory

authored by David Lord · committed by GitHub · parents 0687adf, aaf13a2 · Browse files · 4 files+23 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+23 added−9 removed

  • tests:+13 added−0 removed
  • other:+10 added−9 removed

4 files+23 added−9 removed

modified:jinja2/utils.py+6 added-7 removed
6 unmodified lines
78 :copyright: (c) 2017 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""11import os12import re13import json13import errno14import warnings15from collections import deque16from threading import Lock17from jinja2._compat import text_type, string_types, implements_iterator, \
128 unmodified lines
146147148def open_if_exists(filename, mode='rb'):149 """Returns a file descriptor for the filename if that file exists,150 otherwise `None`.150 otherwise ``None``.151 """152 try:153 return open(filename, mode)154 except IOError as e:155 if e.errno not in (errno.ENOENT, errno.EISDIR, errno.EINVAL):156 raise152 if not os.path.isfile(filename):153 return None154155 return open(filename, mode)156157158def object_type_repr(obj):159 """Returns the name of the object's type. For some recognized160 singletons the name of the object is returned instead. (For161 example for `None` and `Ellipsis`).
482 unmodified lines
added:tests/res/templates2/foo+2 added
1Looks like the start of templates/foo/test.html2Tested by test_filesystem_loader_overlapping_names
modified:tests/test_loader.py+11 added
42 unmodified lines
43 tmpl = env.get_template('foo/test.html')44 assert tmpl.render().strip() == 'FOO'45 pytest.raises(TemplateNotFound, env.get_template, 'missing.html')4647 def test_filesystem_loader_overlapping_names(self, filesystem_loader):48 res = os.path.dirname(filesystem_loader.searchpath[0])49 t2_dir = os.path.join(res, "templates2")50 # Make "foo" show up before "foo/test.html".51 filesystem_loader.searchpath.insert(0, t2_dir)52 e = Environment(loader=filesystem_loader)53 e.get_template("foo")54 # This would raise NotADirectoryError if "t2/foo" wasn't skipped.55 e.get_template("foo/test.html")565758 def test_choice_loader(self, choice_loader):59 env = Environment(loader=choice_loader)60 tmpl = env.get_template('justdict.html')61 assert tmpl.render().strip() == 'FOO'
184 unmodified lines
modified:CHANGES.rst+4 added-2 removed
1.. currentmodule:: jinja223Version 2.114------------3Version 2.11.04--------------56Unreleased78- Async support is only loaded the first time an
27 unmodified lines
36 tests. :pr:`824`37- The environment's ``finalize`` function is only applied to the38 output of expressions (constant or not), not static template data.39 :issue:`63`40- When providing multiple paths to ``FileSystemLoader``, a template41 can have the same name as a directory. :issue:`821`424344Version 2.10.345--------------
629 unmodified lines