changeset 581:e9e1239960f5 stable-0.4.x

Ported [693:694] to 0.4.x branch.
author cmlenz
date Tue, 31 Jul 2007 21:54:58 +0000
parents 7fa1192c9da8
children 60a906b93acd
files ChangeLog genshi/template/eval.py genshi/template/tests/eval.py genshi/util.py
diffstat 4 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Version 0.4.4
+http://svn.edgewall.org/repos/genshi/tags/0.4.4/
+(?, from branches/stable/0.4.x)
+
+ * Fixed augmented assignment to local variables in Python code blocks.
+
+
 Version 0.4.3
 http://svn.edgewall.org/repos/genshi/tags/0.4.3/
 (?, from branches/stable/0.4.x)
--- a/genshi/template/eval.py
+++ b/genshi/template/eval.py
@@ -247,7 +247,8 @@
         return {
             '_lookup_name': cls.lookup_name,
             '_lookup_attr': cls.lookup_attr,
-            '_lookup_item': cls.lookup_item
+            '_lookup_item': cls.lookup_item,
+            'UndefinedError': UndefinedError
         }
     globals = classmethod(globals)
 
@@ -671,7 +672,8 @@
         return node
 
     def visitAugAssign(self, node):
-        if isinstance(node.node, ast.Name):
+        if isinstance(node.node, ast.Name) and (not self.locals
+                or node.node.name not in flatten(self.locals[-1])):
             name = node.node.name
             node.node = ast.Subscript(ast.Name('data'), 'OP_APPLY',
                                       [ast.Const(name)])
--- a/genshi/template/tests/eval.py
+++ b/genshi/template/tests/eval.py
@@ -540,6 +540,15 @@
     def test_local_augmented_assign(self):
         Suite("x = 1; x += 42; assert x == 43").execute({})
 
+    def test_augmented_assign_in_def(self):
+        d = {}
+        Suite("""def foo():
+    i = 1
+    i += 1
+    return i
+x = foo()""").execute(d)
+        self.assertEqual(2, d['x'])
+
     def test_assign_in_list(self):
         suite = Suite("[d['k']] = 'foo',; assert d['k'] == 'foo'")
         d = {"k": "bar"}
--- a/genshi/util.py
+++ b/genshi/util.py
@@ -15,6 +15,11 @@
 
 import htmlentitydefs
 import re
+try:
+    set
+except NameError:
+    from sets import ImmutableSet as frozenset
+    from sets import Set as set
 
 __docformat__ = 'restructuredtext en'
 
@@ -152,7 +157,7 @@
     """
     retval = []
     for item in items:
-        if isinstance(item, (list, tuple)):
+        if isinstance(item, (frozenset, list, set, tuple)):
             retval += flatten(item)
         else:
             retval.append(item)
Copyright (C) 2012-2017 Edgewall Software