Edgewall Software

Changeset 1102 for trunk


Ignore:
Timestamp:
Apr 15, 2010, 11:38:21 PM (13 years ago)
Author:
cmlenz
Message:

Looks like the 'decorators' field in the AST was renamed to 'decorator_list' in Python 2.6, so look for both. See #379.

Location:
trunk/genshi/template
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/genshi/template/astutil.py

    r1078 r1102  
    131131
    132132    # FunctionDef(identifier name, arguments args,
    133     #                           stmt* body, expr* decorators)
     133    #                           stmt* body, expr* decorator_list)
    134134    def visit_FunctionDef(self, node):
    135         for decorator in getattr(node, 'decorators', ()):
     135        decarators = ()
     136        if hasattr(node, 'decorator_list'):
     137            decorators = getattr(node, 'decorator_list')
     138        else: # different name in earlier Python versions
     139            decorators = getattr(node, 'decorators', ())
     140        for decorator in decorators:
    136141            self._new_line()
    137142            self._write('@')
  • trunk/genshi/template/tests/eval.py

    r1091 r1102  
    589589        self.assertEqual(['foo', 'bar'], data['x'])
    590590
     591    def test_def_with_decorator(self):
     592        suite = Suite("""
     593def lower(fun):
     594    return lambda: fun().lower()
     595
     596@lower
     597def say_hi():
     598    return 'Hi!'
     599
     600result = say_hi()
     601""")
     602        data = {}
     603        suite.execute(data)
     604        self.assertEqual('hi!', data['result'])
     605
    591606    def test_delete(self):
    592607        suite = Suite("""foo = 42
Note: See TracChangeset for help on using the changeset viewer.