simplified from imports
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 15 May 2008 21:18:07 +0000 (23:18 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 15 May 2008 21:18:07 +0000 (23:18 +0200)
--HG--
branch : trunk

jinja2/compiler.py
jinja2/parser.py

index 2839264f514caf1939c7b89165f6493513032839..0b8ae964662a5e256cd0d847ae4f1e63ab775e18 100644 (file)
@@ -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
index 19ee166ec3da061bc103174205234979ba39a6ba..d9bf4928c64766fec8b59f8411462135f8d541c7 100644 (file)
@@ -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',