Fast path for disabled template load explain.
This commit is contained in:
parent
883cb7cedc
commit
96ec24f6e0
1 changed files with 20 additions and 11 deletions
|
|
@ -52,27 +52,36 @@ class DispatchingJinjaLoader(BaseLoader):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
def get_source(self, environment, template):
|
def get_source(self, environment, template):
|
||||||
explain = self.app.config['EXPLAIN_TEMPLATE_LOADING']
|
if self.app.config['EXPLAIN_TEMPLATE_LOADING']:
|
||||||
|
return self._get_source_explained(environment, template)
|
||||||
|
return self._get_source_fast(environment, template)
|
||||||
|
|
||||||
|
def _get_source_explained(self, environment, template):
|
||||||
attempts = []
|
attempts = []
|
||||||
tmplrv = None
|
trv = None
|
||||||
|
|
||||||
for srcobj, loader in self._iter_loaders(template):
|
for srcobj, loader in self._iter_loaders(template):
|
||||||
try:
|
try:
|
||||||
rv = loader.get_source(environment, template)
|
rv = loader.get_source(environment, template)
|
||||||
if tmplrv is None:
|
if trv is None:
|
||||||
tmplrv = rv
|
trv = rv
|
||||||
if not explain:
|
|
||||||
break
|
|
||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
rv = None
|
rv = None
|
||||||
attempts.append((loader, srcobj, rv))
|
attempts.append((loader, srcobj, rv))
|
||||||
|
|
||||||
if explain:
|
from .debughelpers import explain_template_loading_attempts
|
||||||
from .debughelpers import explain_template_loading_attempts
|
explain_template_loading_attempts(self.app, template, attempts)
|
||||||
explain_template_loading_attempts(self.app, template, attempts)
|
|
||||||
|
|
||||||
if tmplrv is not None:
|
if trv is not None:
|
||||||
return tmplrv
|
return trv
|
||||||
|
raise TemplateNotFound(template)
|
||||||
|
|
||||||
|
def _get_source_fast(self, environment, template):
|
||||||
|
for srcobj, loader in self._iter_loaders(template):
|
||||||
|
try:
|
||||||
|
return loader.get_source(environment, template)
|
||||||
|
except TemplateNotFound:
|
||||||
|
continue
|
||||||
raise TemplateNotFound(template)
|
raise TemplateNotFound(template)
|
||||||
|
|
||||||
def _iter_loaders(self, template):
|
def _iter_loaders(self, template):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue