From f0a65a68a609a5a639f7c6269741f5defb5abbe2 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 6 Nov 2007 19:29:09 +0100 Subject: [PATCH] fixed macro return value (for autoescaping) and avoided double free in BaseContext_clear --HG-- branch : trunk --- jinja/_speedups.c | 1 + jinja/datastructure.py | 1 - jinja/translators/python.py | 2 +- jinja/utils.py | 8 ++++++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jinja/_speedups.c b/jinja/_speedups.c index eba129b..198b7a0 100644 --- a/jinja/_speedups.c +++ b/jinja/_speedups.c @@ -70,6 +70,7 @@ BaseContext_clear(BaseContext *self) current = tmp->prev; PyMem_Free(tmp); } + self->current = NULL; return 0; } diff --git a/jinja/datastructure.py b/jinja/datastructure.py index 56e07b3..8ad6f5a 100644 --- a/jinja/datastructure.py +++ b/jinja/datastructure.py @@ -8,7 +8,6 @@ :copyright: 2007 by Armin Ronacher. :license: BSD, see LICENSE for more details. """ - from jinja.exceptions import TemplateSyntaxError, TemplateRuntimeError _missing = object() diff --git a/jinja/translators/python.py b/jinja/translators/python.py index 04b9aed..f07fdc3 100644 --- a/jinja/translators/python.py +++ b/jinja/translators/python.py @@ -738,7 +738,7 @@ class PythonTranslator(Translator): write('context.pop()') write('if 0: yield None') self.indention -= 1 - buf.append(self.indent('context[%r] = buffereater(macro)' % + buf.append(self.indent('context[%r] = buffereater(macro, True)' % node.name)) self.used_utils.add('buffereater') diff --git a/jinja/utils.py b/jinja/utils.py index 9461990..7fe5d2e 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -17,6 +17,7 @@ import string from types import MethodType, FunctionType from jinja import nodes from jinja.exceptions import SecurityException, TemplateNotFound +from jinja.datastructure import TemplateData # the python2.4 version of deque is missing the remove method # because a for loop with a lookup for the missing value written @@ -363,14 +364,17 @@ def pformat(obj, verbose=False): return pformat(obj) -def buffereater(f): +def buffereater(f, template_data=False): """ Used by the python translator to capture output of substreams. (macros, filter sections etc) """ def wrapped(*a, **kw): __traceback_hide__ = True - return capture_generator(f(*a, **kw)) + rv = capture_generator(f(*a, **kw)) + if template_data: + rv = TemplateData(rv) + return rv return wrapped -- 2.26.2