comparison genshi/template/astutil.py @ 902:09cc3627654c experimental-inline

Sync `experimental/inline` branch with [source:trunk@1126].
author cmlenz
date Fri, 23 Apr 2010 21:08:26 +0000
parents 1837f39efd6f
children 95d62e239f60
comparison
equal deleted inserted replaced
830:de82830f8816 902:09cc3627654c
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # 2 #
3 # Copyright (C) 2008 Edgewall Software 3 # Copyright (C) 2008-2010 Edgewall Software
4 # All rights reserved. 4 # All rights reserved.
5 # 5 #
6 # This software is licensed as described in the file COPYING, which 6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms 7 # you should have received as part of this distribution. The terms
8 # are also available at http://genshi.edgewall.org/wiki/License. 8 # are also available at http://genshi.edgewall.org/wiki/License.
16 try: 16 try:
17 import _ast 17 import _ast
18 except ImportError: 18 except ImportError:
19 from genshi.template.ast24 import _ast, parse 19 from genshi.template.ast24 import _ast, parse
20 else: 20 else:
21 if not hasattr(_ast, 'AST'):
22 from genshi.template.astgae import restore
23 restore(_ast)
24 def parse(source, mode): 21 def parse(source, mode):
25 return compile(source, '', mode, _ast.PyCF_ONLY_AST) 22 return compile(source, '', mode, _ast.PyCF_ONLY_AST)
26 23
27 24
28 __docformat__ = 'restructuredtext en' 25 __docformat__ = 'restructuredtext en'
131 else: 128 else:
132 first = False 129 first = False
133 self._write('**' + node.kwarg) 130 self._write('**' + node.kwarg)
134 131
135 # FunctionDef(identifier name, arguments args, 132 # FunctionDef(identifier name, arguments args,
136 # stmt* body, expr* decorators) 133 # stmt* body, expr* decorator_list)
137 def visit_FunctionDef(self, node): 134 def visit_FunctionDef(self, node):
138 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:
139 self._new_line() 141 self._new_line()
140 self._write('@') 142 self._write('@')
141 self.visit(decorator) 143 self.visit(decorator)
142 self._new_line() 144 self._new_line()
143 self._write('def ' + node.name + '(') 145 self._write('def ' + node.name + '(')
652 self.visit(node.dims[0]) 654 self.visit(node.dims[0])
653 for dim in node.dims[1:]: 655 for dim in node.dims[1:]:
654 self._write(', ') 656 self._write(', ')
655 self.visit(dim) 657 self.visit(dim)
656 else: 658 else:
657 raise NotImplemented, 'Slice type not implemented' 659 raise NotImplemented('Slice type not implemented')
658 _process_slice(node.slice) 660 _process_slice(node.slice)
659 self._write(']') 661 self._write(']')
660 662
661 # Name(identifier id, expr_context ctx) 663 # Name(identifier id, expr_context ctx)
662 def visit_Name(self, node): 664 def visit_Name(self, node):
738 visit_With = _clone 740 visit_With = _clone
739 visit_Raise = _clone 741 visit_Raise = _clone
740 visit_TryExcept = _clone 742 visit_TryExcept = _clone
741 visit_TryFinally = _clone 743 visit_TryFinally = _clone
742 visit_Assert = _clone 744 visit_Assert = _clone
745 visit_ExceptHandler = _clone
743 746
744 visit_Import = _clone 747 visit_Import = _clone
745 visit_ImportFrom = _clone 748 visit_ImportFrom = _clone
746 visit_Exec = _clone 749 visit_Exec = _clone
747 visit_Global = _clone 750 visit_Global = _clone
Copyright (C) 2012-2017 Edgewall Software