Loads a template. This method looks up the template in the cache or loads one by calling :meth:`get_source`. Subclasses should not override this method as loaders working on collections of other loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`) will n
(self, environment, name, globals=None)
| 98 | |
| 99 | @internalcode |
| 100 | def load(self, environment, name, globals=None): |
| 101 | """Loads a template. This method looks up the template in the cache |
| 102 | or loads one by calling :meth:`get_source`. Subclasses should not |
| 103 | override this method as loaders working on collections of other |
| 104 | loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`) |
| 105 | will not call this method but `get_source` directly. |
| 106 | """ |
| 107 | code = None |
| 108 | if globals is None: |
| 109 | globals = {} |
| 110 | |
| 111 | # first we try to get the source for this template together |
| 112 | # with the filename and the uptodate function. |
| 113 | source, filename, uptodate = self.get_source(environment, name) |
| 114 | |
| 115 | # try to load the code from the bytecode cache if there is a |
| 116 | # bytecode cache configured. |
| 117 | bcc = environment.bytecode_cache |
| 118 | if bcc is not None: |
| 119 | bucket = bcc.get_bucket(environment, name, filename, source) |
| 120 | code = bucket.code |
| 121 | |
| 122 | # if we don't have code so far (not cached, no longer up to |
| 123 | # date) etc. we compile the template |
| 124 | if code is None: |
| 125 | code = environment.compile(source, name, filename) |
| 126 | |
| 127 | # if the bytecode cache is available and the bucket doesn't |
| 128 | # have a code so far, we give the bucket the new code and put |
| 129 | # it back to the bytecode cache. |
| 130 | if bcc is not None and bucket.code is None: |
| 131 | bucket.code = code |
| 132 | bcc.set_bucket(bucket) |
| 133 | |
| 134 | return environment.template_class.from_code(environment, code, |
| 135 | globals, uptodate) |
| 136 | |
| 137 | |
| 138 | class FileSystemLoader(BaseLoader): |
no test coverage detected