Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def render_function(template, values, options):
if options.get('is_string'):
tmpl = env.from_string(template)
else:
try:
tmpl = env.get_template(template)
except TemplateNotFound:
return
return tmpl.render(**values)
def get_source(self, environment, name, parent):
"""
Override this method to get the source for a template.
"""
raise TemplateNotFound(name)
def parse(self, environment, name, parent):
for loader in self.loaders:
try:
return loader.parse(environment, name, parent)
except TemplateNotFound, e:
if e.name != name:
raise
continue
raise TemplateNotFound(name)
def get_source(self, environment, name, parent):
rv = self.loader_func(name)
if rv is None:
raise TemplateNotFound(name)
if isinstance(rv, str):
return rv.decode(environment.template_charset)
return rv
def get_source(self, environment, name, parent):
name = name.replace('/', path.sep)
if name.startswith('!'):
name = name[1:]
if not path.exists(path.join(self.basepath, name)):
raise TemplateNotFound(name)
filename = path.join(self.basepath, name)
elif path.isabs(name):
if not path.exists(name):
raise TemplateNotFound(name)
filename = name
else:
for searchpath in self.searchpaths:
if path.exists(path.join(searchpath, name)):
filename = path.join(searchpath, name)
break
else:
raise TemplateNotFound(name)
f = codecs.open(filename, 'r', environment.template_charset)
try:
return f.read()
finally:
if name.startswith('!'):
name = name[1:]
if not path.exists(path.join(self.basepath, name)):
raise TemplateNotFound(name)
filename = path.join(self.basepath, name)
elif path.isabs(name):
if not path.exists(name):
raise TemplateNotFound(name)
filename = name
else:
for searchpath in self.searchpaths:
if path.exists(path.join(searchpath, name)):
filename = path.join(searchpath, name)
break
else:
raise TemplateNotFound(name)
f = codecs.open(filename, 'r', environment.template_charset)
try:
return f.read()
finally:
f.close()