From: Armin Ronacher Date: Mon, 12 Mar 2007 20:06:35 +0000 (+0100) Subject: [svn] fixed empty block bug X-Git-Tag: 2.0rc1~447 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4e0cd087ccef6576d721fde3d2ae6a157f0dc6cd;p=jinja2.git [svn] fixed empty block bug --HG-- branch : trunk --- diff --git a/jinja/translators/python.py b/jinja/translators/python.py index a891f02..db78843 100644 --- a/jinja/translators/python.py +++ b/jinja/translators/python.py @@ -301,7 +301,8 @@ class PythonTranslator(Translator): lines.append(self.handle_node(n)) # the template body - rv = self.handle_node_list(node) + body_lines = [self.handle_node(n) for n in node] + print list(node) # add translation helpers if required if self.require_translations: @@ -312,7 +313,7 @@ class PythonTranslator(Translator): ' return translator.gettext(s) % (r or {})\n' ' return translator.ngettext(s, p, r[n]) % (r or {})' ) - lines.append(rv) + lines.extend(body_lines) lines.append(' if False:\n yield None') return '\n'.join(lines) @@ -529,7 +530,7 @@ class PythonTranslator(Translator): """ rv = self.handle_node(node.body) if not rv: - return + return '' buf = [] write = lambda x: buf.append(self.indent(x)) diff --git a/jinja/utils.py b/jinja/utils.py index d122da6..832cfdb 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -88,6 +88,9 @@ def raise_template_exception(template, exception, filename, lineno, context): Raise an exception "in a template". Return a traceback object. """ + # some traceback systems allow to skip blocks + __traceback_hide__ = True + offset = '\n' * (lineno - 1) code = compile(offset + 'raise __exception_to_raise__', filename, 'exec') namespace = context.to_dict() @@ -221,7 +224,10 @@ class CacheDict(object): def clear(self): self._mapping.clear() - del self._queue[:] + try: + self._queue.clear() + except AttributeError: + del self._queue[:] def __contains__(self, key): return key in self._mapping