本文整理汇总了Python中genshi.template.astutil.ASTTransformer类的典型用法代码示例。如果您正苦于以下问题:Python ASTTransformer类的具体用法?Python ASTTransformer怎么用?Python ASTTransformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ASTTransformer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_Attribute
def visit_Attribute(self, node):
if not isinstance(node.ctx, _ast.Load):
return ASTTransformer.visit_Attribute(self, node)
func = _new(_ast.Name, '_lookup_attr', _ast.Load())
args = [self.visit(node.value), _new(_ast.Str, node.attr)]
return _new(_ast.Call, func, args, [])
示例2: visit_Subscript
def visit_Subscript(self, node):
if not isinstance(node.ctx, _ast.Load) or not isinstance(node.slice, _ast.Index):
return ASTTransformer.visit_Subscript(self, node)
func = _new(_ast.Name, "_lookup_item", _ast.Load())
args = [self.visit(node.value), _new(_ast.Tuple, (self.visit(node.slice.value),), _ast.Load())]
return _new(_ast.Call, func, args, [])
示例3: visit_ClassDef
def visit_ClassDef(self, node):
if len(self.locals) > 1:
self.locals[-1].add(node.name)
self.locals.append(set())
try:
return ASTTransformer.visit_ClassDef(self, node)
finally:
self.locals.pop()
示例4: visit_FunctionDef
def visit_FunctionDef(self, node):
if len(self.locals) > 1:
self.locals[-1].add(node.name)
self.locals.append(self._extract_names(node.args))
try:
return ASTTransformer.visit_FunctionDef(self, node)
finally:
self.locals.pop()
示例5: visit_ImportFrom
def visit_ImportFrom(self, node):
if [a.name for a in node.names] == ['*']:
if has_star_import_bug:
# This is a Python 2.4 bug. Only if we have a broken Python
# version do we need to apply this hack
node = _new(_ast.Expr, _new(_ast.Call,
_new(_ast.Name, '_star_import_patch'), [
_new(_ast.Name, '__data__'),
_new(_ast.Str, node.module)
], (), ()))
return node
if len(self.locals) > 1:
self.locals[-1].update(self._extract_names(node))
return ASTTransformer.visit_ImportFrom(self, node)
示例6: visit_Lambda
def visit_Lambda(self, node):
self.locals.append(self._extract_names(node.args))
try:
return ASTTransformer.visit_Lambda(self, node)
finally:
self.locals.pop()
示例7: visit_Import
def visit_Import(self, node):
if len(self.locals) > 1:
self.locals[-1].update(self._extract_names(node))
return ASTTransformer.visit_Import(self, node)
示例8: visit_For
def visit_For(self, node):
self.locals.append(set())
try:
return ASTTransformer.visit_For(self, node)
finally:
self.locals.pop()