[svn] choice loader now doesn't screen template not found exception of imports / extends
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent b4e1588 · Browse files · 4 files·+32 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+32 added−9 removed
- tests:+10 added−0 removed
- other:+22 added−9 removed
Provenance
- Commit
f61000d- Tree
f737d90- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
b4e1588
4 files changed+32 added−9 removed
modified:jinja/exceptions.py+3 added-2 removed
59 unmodified lines60 """61 Raised if a template does not exist.62 """63 64- def __init__(self, message):65- IOError.__init__(self, message)64+ def __init__(self, name):65+ IOError.__init__(self, name)66+ self.name = name67 68 69 class TemplateSyntaxError(SyntaxError, TemplateError):70 """14 unmodified linesmodified:jinja/loaders.py+19 added-7 removed
124 unmodified lines125 """126 ast = self.parse(environment, name, None)127 return translator.process(environment, ast)128 129+ def get_source(self, environment, name, parent):130+ """131+ Override this method to get the source for a template.132+ """133+ raise TemplateNotFound(name)134 135+136 class CachedLoaderMixin(object):137 """138 Mixin this class to implement simple memory and disk caching.139 """226 unmodified lines366 cache_folder, auto_reload, cache_salt)367 368 def get_source(self, environment, name, parent):369 from pkg_resources import resource_exists, resource_string364- name = '/'.join([self.package_path] + [p for p in name.split('/')365- if p != '..'])366- if not resource_exists(self.package_name, name):370+ path = '/'.join([self.package_path] + [p for p in name.split('/')371+ if p != '..'])372+ if not resource_exists(self.package_name, path):373 raise TemplateNotFound(name)368- contents = resource_string(self.package_name, name)374+ contents = resource_string(self.package_name, path)375 return contents.decode(environment.template_charset)376 377 def check_source_changed(self, environment, name):378 from pkg_resources import resource_exists, resource_filename122 unmodified lines501 def get_source(self, environment, name, parent):502 for loader in self.loaders:503 try:504 return loader.get_source(environment, name, parent)499- except TemplateNotFound:505+ except TemplateNotFound, e:506+ if e.name != name:507+ raise508 continue509 raise TemplateNotFound(name)510 511 def parse(self, environment, name, parent):512 for loader in self.loaders:513 try:514 return loader.parse(environment, name, parent)507- except TemplateNotFound:515+ except TemplateNotFound, e:516+ if e.name != name:517+ raise518 continue519 raise TemplateNotFound(name)520 521 def load(self, environment, name, translator):522 for loader in self.loaders:523 try:524 return loader.load(environment, name, translator)515- except TemplateNotFound:525+ except TemplateNotFound, e:526+ if e.name != name:527+ raise528 continue529 raise TemplateNotFound(name)added:tests/loaderres/templates/brokenimport.html+1 added
1{% extends "missing.html" %}modified:tests/test_loaders.py+9 added
79 unmodified lines80 pass81 else:82 raise AssertionError('expected template exception')83 84+ # this should raise an TemplateNotFound error with the85+ # correct name86+ try:87+ env.get_template('brokenimport.html')88+ except TemplateNotFound, e:89+ assert e.name == 'missing.html'90+ else:91+ raise AssertionError('expected exception')92 93+94 def test_function_loader():95 env = Environment(loader=function_loader)96 tmpl = env.get_template('justfunction.html')97 assert tmpl.render().strip() == 'FOO'60 unmodified lines