@@ -52,27 +52,36 @@ def __init__(self, app):
52
52
self .app = app
53
53
54
54
def get_source (self , environment , template ):
55
- explain = self .app .config ['EXPLAIN_TEMPLATE_LOADING' ]
55
+ if self .app .config ['EXPLAIN_TEMPLATE_LOADING' ]:
56
+ return self ._get_source_explained (environment , template )
57
+ return self ._get_source_fast (environment , template )
58
+
59
+ def _get_source_explained (self , environment , template ):
56
60
attempts = []
57
- tmplrv = None
61
+ trv = None
58
62
59
63
for srcobj , loader in self ._iter_loaders (template ):
60
64
try :
61
65
rv = loader .get_source (environment , template )
62
- if tmplrv is None :
63
- tmplrv = rv
64
- if not explain :
65
- break
66
+ if trv is None :
67
+ trv = rv
66
68
except TemplateNotFound :
67
69
rv = None
68
70
attempts .append ((loader , srcobj , rv ))
69
71
70
- if explain :
71
- from .debughelpers import explain_template_loading_attempts
72
- explain_template_loading_attempts (self .app , template , attempts )
72
+ from .debughelpers import explain_template_loading_attempts
73
+ explain_template_loading_attempts (self .app , template , attempts )
74
+
75
+ if trv is not None :
76
+ return trv
77
+ raise TemplateNotFound (template )
73
78
74
- if tmplrv is not None :
75
- return tmplrv
79
+ def _get_source_fast (self , environment , template ):
80
+ for srcobj , loader in self ._iter_loaders (template ):
81
+ try :
82
+ return loader .get_source (environment , template )
83
+ except TemplateNotFound :
84
+ continue
76
85
raise TemplateNotFound (template )
77
86
78
87
def _iter_loaders (self , template ):
0 commit comments