From: Armin Ronacher Date: Thu, 15 May 2008 21:18:07 +0000 (+0200) Subject: simplified from imports X-Git-Tag: 2.0rc1~54 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a78d276ef76ccfaff017363b3dcc78099da4ddd3;p=jinja2.git simplified from imports --HG-- branch : trunk --- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 2839264..0b8ae96 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -841,6 +841,9 @@ class CodeGenerator(NodeVisitor): self.write('make_module(context.parent, True)') else: self.write('module') + + var_names = [] + discarded_names = [] for name in node.names: if isinstance(name, tuple): name, alias = name @@ -857,9 +860,25 @@ class CodeGenerator(NodeVisitor): 'the requested name ' + repr(name), name)) self.outdent() if frame.toplevel: - self.writeline('context.vars[%r] = l_%s' % (alias, alias)) + var_names.append(alias) if not alias.startswith('__'): - self.writeline('context.exported_vars.discard(%r)' % alias) + discarded_names.append(alias) + + if var_names: + if len(var_names) == 1: + name = var_names[0] + self.writeline('context.vars[%r] = l_%s' % (name, name)) + else: + self.writeline('context.vars.update({%s})' % ', '.join( + '%r: l_%s' % (name, name) for name in var_names + )) + if discarded_names: + if len(discarded_names) == 1: + self.writeline('context.exported_vars.discard(%r)' % + discarded_names[0]) + else: + self.writeline('context.exported_vars.difference_' + 'update((%s))' % ', '.join(map(repr, discarded_names))) def visit_For(self, node, frame): # when calculating the nodes for the inner frame we have to exclude diff --git a/jinja2/parser.py b/jinja2/parser.py index 19ee166..d9bf492 100644 --- a/jinja2/parser.py +++ b/jinja2/parser.py @@ -9,7 +9,7 @@ :license: BSD, see LICENSE for more details. """ from jinja2 import nodes -from jinja2.exceptions import TemplateSyntaxError +from jinja2.exceptions import TemplateSyntaxError, TemplateAssertionError _statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',