当前位置: 首页>>代码示例>>Python>>正文


Python _ast.Attribute方法代码示例

本文整理汇总了Python中_ast.Attribute方法的典型用法代码示例。如果您正苦于以下问题:Python _ast.Attribute方法的具体用法?Python _ast.Attribute怎么用?Python _ast.Attribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_ast的用法示例。


在下文中一共展示了_ast.Attribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visit_attribute

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Attribute [as 别名]
def visit_attribute(self, node: _ast.Attribute):  # value, attr, ctx
        value = self._run(node.value)
        t = type(value)
        try:
            if value in self.allowed_modules:
                if node.attr in self.allowed_modules[value]:
                    return getattr(value, node.attr)
                raise BadSyntax(f'You can not access `{node.attr}` attribute')
            if value in self.allowed_class_properties:
                if node.attr in self.allowed_class_properties[value]:
                    return getattr(value, node.attr)
                raise BadSyntax(f'You can not access `{node.attr}` attribute')
        except TypeError:
            pass
        if t in self.allowed_instance_properties:
            if node.attr in self.allowed_instance_properties[t]:
                return getattr(value, node.attr)
            raise BadSyntax(f'You can not access `{node.attr}` attribute')
        raise BadSyntax(f'You can not access attributes of {t}') 
开发者ID:item4,项目名称:yui,代码行数:21,代码来源:calc.py

示例2: make_attribute

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Attribute [as 别名]
def make_attribute(i, bytecode, context=None):
    arg = bytecode[i][3]
    attr_path = []
    j = i
    while True:
      prev_op, prev_arg =  bytecode[j][2], bytecode[j][3]
      if prev_op not in (LOAD_ATTR, STORE_ATTR, DELETE_ATTR):
        break
      attr_path.append(prev_arg)
      if j < 0:
        break
      j -= 1
    # The parent of the ATTR can be whatever expression...
    i, name = Statement.make_expr(j, bytecode)
    attr = name
    while True:
      if not attr_path:
        break
      attr_name = attr_path.pop()
      attr = _ast.Attribute(attr, attr_name, context)
    return i, attr 
开发者ID:neuroo,项目名称:equip,代码行数:23,代码来源:stmt.py

示例3: visit_Name

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Attribute [as 别名]
def visit_Name( self, node ):
    new_node = LocalVar( id=node.id )
    new_node._name = node.id
    return ast.copy_location( new_node, node )


#-------------------------------------------------------------------------
# ReorderAST
#-------------------------------------------------------------------------
# Reorders an AST branch beginning with the indicated node.  Intended
# for inverting the order of Name/Attribute chains so that the Name
# node comes first, followed by chains of Attribute/Subscript nodes.
#
# This visitor will also insert Self nodes to represent references to the
# self variable, and remove Index nodes which seem to serve no useful
# purpose. 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:18,代码来源:ast_transformer.py

示例4: visit_Num

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Attribute [as 别名]
def visit_Num( self, node ):
    # Name generation
    node._name = str( node.n )
    self.stack.append( node )

#------------------------------------------------------------------------
# Self
#------------------------------------------------------------------------
# New AST Node for references to self. Based on Attribute node. 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:11,代码来源:ast_transformer.py

示例5: get_rules

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Attribute [as 别名]
def get_rules():
	
	with open(PARSER_FILE) as f:
		src = f.read()
	
	rules = collections.OrderedDict()
	for node in ast.parse(src).body:
		
		if not isinstance(node, _ast.FunctionDef):
			continue
		
		if not node.decorator_list:
			continue
		
		assert len(node.decorator_list) == 1
		decorator = node.decorator_list[0]
		if not isinstance(decorator, _ast.Call):
			continue
		
		func = decorator.func
		if not isinstance(func, _ast.Attribute):
			continue
		
		assert func.attr == 'production'
		ln = decorator.args[0].s
		name, match = ln.split(' : ', 1)
		rules.setdefault(name, []).append(tuple(match.split()))
	
	return rules 
开发者ID:djc,项目名称:runa,代码行数:31,代码来源:grammar.py


注:本文中的_ast.Attribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。