當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。