# HG changeset patch # User cmlenz # Date 1271367501 0 # Node ID 27d210790d2719a3015de21f3f3578ebbd51c691 # Parent abfabaea906f608ca83bc4485ac100ce70f82267 Looks like the 'decorators' field in the AST was renamed to 'decorator_list' in Python 2.6, so look for both. See #379. diff --git a/genshi/template/astutil.py b/genshi/template/astutil.py --- a/genshi/template/astutil.py +++ b/genshi/template/astutil.py @@ -130,9 +130,14 @@ self._write('**' + node.kwarg) # FunctionDef(identifier name, arguments args, - # stmt* body, expr* decorators) + # stmt* body, expr* decorator_list) def visit_FunctionDef(self, node): - for decorator in getattr(node, 'decorators', ()): + decarators = () + if hasattr(node, 'decorator_list'): + decorators = getattr(node, 'decorator_list') + else: # different name in earlier Python versions + decorators = getattr(node, 'decorators', ()) + for decorator in decorators: self._new_line() self._write('@') self.visit(decorator) diff --git a/genshi/template/tests/eval.py b/genshi/template/tests/eval.py --- a/genshi/template/tests/eval.py +++ b/genshi/template/tests/eval.py @@ -588,6 +588,21 @@ suite.execute(data) self.assertEqual(['foo', 'bar'], data['x']) + def test_def_with_decorator(self): + suite = Suite(""" +def lower(fun): + return lambda: fun().lower() + +@lower +def say_hi(): + return 'Hi!' + +result = say_hi() +""") + data = {} + suite.execute(data) + self.assertEqual('hi!', data['result']) + def test_delete(self): suite = Suite("""foo = 42 del foo