ast = self.parse(environment, name, None)
return translator.process(environment, ast)
+ def get_source(self, environment, name, parent):
+ """
+ Override this method to get the source for a template.
+ """
+ raise TemplateNotFound(name)
+
class CachedLoaderMixin(object):
"""
def get_source(self, environment, name, parent):
from pkg_resources import resource_exists, resource_string
- name = '/'.join([self.package_path] + [p for p in name.split('/')
- if p != '..'])
- if not resource_exists(self.package_name, name):
+ path = '/'.join([self.package_path] + [p for p in name.split('/')
+ if p != '..'])
+ if not resource_exists(self.package_name, path):
raise TemplateNotFound(name)
- contents = resource_string(self.package_name, name)
+ contents = resource_string(self.package_name, path)
return contents.decode(environment.template_charset)
def check_source_changed(self, environment, name):
for loader in self.loaders:
try:
return loader.get_source(environment, name, parent)
- except TemplateNotFound:
+ except TemplateNotFound, e:
+ if e.name != name:
+ raise
continue
raise TemplateNotFound(name)
for loader in self.loaders:
try:
return loader.parse(environment, name, parent)
- except TemplateNotFound:
+ except TemplateNotFound, e:
+ if e.name != name:
+ raise
continue
raise TemplateNotFound(name)
for loader in self.loaders:
try:
return loader.load(environment, name, translator)
- except TemplateNotFound:
+ except TemplateNotFound, e:
+ if e.name != name:
+ raise
continue
raise TemplateNotFound(name)
else:
raise AssertionError('expected template exception')
+ # this should raise an TemplateNotFound error with the
+ # correct name
+ try:
+ env.get_template('brokenimport.html')
+ except TemplateNotFound, e:
+ assert e.name == 'missing.html'
+ else:
+ raise AssertionError('expected exception')
+
def test_function_loader():
env = Environment(loader=function_loader)