Commit 66276798 authored by Jérome Perrin's avatar Jérome Perrin

Experiments to demonstrate that we can get a traceback when using a Loader

This is not a patch to add traceback support, just a way to proove that with a loader instead of from_string the traceback properly contain the template code and can be debugged using pdb
parent e9b7c1b2
...@@ -125,6 +125,15 @@ class FolderLoader(RecipeBaseLoader): ...@@ -125,6 +125,15 @@ class FolderLoader(RecipeBaseLoader):
return path return path
return None return None
class MyLoader(BaseLoader):
def __init__(self, file_name, source):
self.file_name = file_name
self.source = source
def get_source(self, environment, template):
return self.source, self.file_name, lambda: True
LOADER_TYPE_DICT = { LOADER_TYPE_DICT = {
'rawfile': (FileLoader, EXPRESSION_HANDLER['raw']), 'rawfile': (FileLoader, EXPRESSION_HANDLER['raw']),
'file': (FileLoader, getKey), 'file': (FileLoader, getKey),
...@@ -140,9 +149,11 @@ class Recipe(object): ...@@ -140,9 +149,11 @@ class Recipe(object):
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
template = options['template'] template = options['template']
if template.startswith('inline:'): if template.startswith('inline:'):
self.template_name = "inline"
template = template[7:].lstrip('\r\n') template = template[7:].lstrip('\r\n')
self.get_template = lambda: template self.get_template = lambda: template
else: else:
self.template_name = template
template = zc.buildout.download.Download( template = zc.buildout.download.Download(
buildout['buildout'], buildout['buildout'],
hash_name=True, hash_name=True,
...@@ -212,9 +223,9 @@ class Recipe(object): ...@@ -212,9 +223,9 @@ class Recipe(object):
Environment( Environment(
extensions=self.extension_list, extensions=self.extension_list,
undefined=StrictUndefined, undefined=StrictUndefined,
loader=self.loader, loader=MyLoader(self.template_name, self.get_template())
).from_string( ).get_template(
self.get_template(), self.template_name
).render( ).render(
**self.context **self.context
) )
......
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