Commit 9db182e8 authored by Yusei Tahara's avatar Yusei Tahara

jinja2_template.py: Improve the previous change. Query cache before download/read template.

parent f8b08cbc
...@@ -210,29 +210,25 @@ class Recipe(object): ...@@ -210,29 +210,25 @@ class Recipe(object):
if self.once and os.path.exists(self.once): if self.once and os.path.exists(self.once):
return return
template = self.template template = self.template
env = self.env
if template.startswith('inline:'): if template.startswith('inline:'):
source = template[7:].lstrip('\r\n') source = template[7:].lstrip('\r\n')
template = '<inline>' template = '<inline>'
compiled_source = env.compile(source, filename=template)
else: else:
template = zc.buildout.download.Download( try:
self.buildout['buildout'], compiled_source = compiled_source_cache[self.template]
hash_name=True, except KeyError:
)( template = zc.buildout.download.Download(
template, self.buildout['buildout'],
md5sum=self.md5sum, hash_name=True,
)[0] )(
with open(template, 'rb') as f: template,
source = f.read().decode(self.encoding) md5sum=self.md5sum,
env = self.env )[0]
with open(template, 'rb') as f:
# get compiled source source = f.read().decode(self.encoding)
if template == '<inline>': compiled_source_cache[self.template] = compiled_source = env.compile(source, filename=template)
compiled_source = env.compile(source, filename=template)
else:
try:
compiled_source = compiled_source_cache[template]
except KeyError:
compiled_source_cache[template] = compiled_source = env.compile(source, filename=template)
template = env.template_class.from_code(env, template = env.template_class.from_code(env,
compiled_source, compiled_source,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment