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


Python _ast.Store方法代码示例

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


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

示例1: visit_attribute

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def visit_attribute(self, node, parent):
        """visit an Attribute node by returning a fresh instance of it"""
        context = _get_context(node)
        if context == astroid.Del:
            # FIXME : maybe we should reintroduce and visit_delattr ?
            # for instance, deactivating assign_ctx
            newnode = nodes.DelAttr(node.attr, node.lineno, node.col_offset,
                                    parent)
        elif context == astroid.Store:
            newnode = nodes.AssignAttr(node.attr, node.lineno, node.col_offset,
                                       parent)
            # Prohibit a local save if we are in an ExceptHandler.
            if not isinstance(parent, astroid.ExceptHandler):
                self._delayed_assattr.append(newnode)
        else:
            newnode = nodes.Attribute(node.attr, node.lineno, node.col_offset,
                                      parent)
        newnode.postinit(self.visit(node.value, newnode))
        return newnode 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:21,代码来源:rebuilder.py

示例2: visit_name

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def visit_name(self, node, parent):
        """visit a Name node by returning a fresh instance of it"""
        context = _get_context(node)
        # True and False can be assigned to something in py2x, so we have to
        # check first the context.
        if context == astroid.Del:
            newnode = nodes.DelName(node.id, node.lineno, node.col_offset,
                                    parent)
        elif context == astroid.Store:
            newnode = nodes.AssignName(node.id, node.lineno, node.col_offset,
                                       parent)
        elif node.id in CONST_NAME_TRANSFORMS:
            newnode = nodes.Const(CONST_NAME_TRANSFORMS[node.id],
                                  getattr(node, 'lineno', None),
                                  getattr(node, 'col_offset', None), parent)
            return newnode
        else:
            newnode = nodes.Name(node.id, node.lineno, node.col_offset, parent)
        # XXX REMOVE me :
        if context in (astroid.Del, astroid.Store): # 'Aug' ??
            self._save_assignment(newnode)
        return newnode 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:24,代码来源:rebuilder.py

示例3: make_assign_chained

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def make_assign_chained(i, bytecode):
    store_exprs = []
    value_exprs = []
    store_state, value_state = True, False

    while i >= 0:
      op, arg = bytecode[i][2], bytecode[i][3]
      if store_state:
        if op == DUP_TOP:
          prev_op = bytecode[i - 1][2] if i > 0 else -1
          if prev_op not in STORE_OPCODES:
            value_state = True
            store_state = False
        elif op in STORE_OPCODES:
          i, store_stmt = Statement.make_expr(i, bytecode, context=_ast.Store())
          store_exprs.insert(0, store_stmt)
      elif value_state:
        i, value_exprs = Statement.make_expr(i, bytecode)
        break
      i -= 1

    store_exprs = _ast.Tuple(store_exprs, _ast.Store())
    return i, _ast.Assign([store_exprs], value_exprs) 
开发者ID:neuroo,项目名称:equip,代码行数:25,代码来源:stmt.py

示例4: NAME

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def NAME(self, node):
        """
        Handle occurrence of Name (which can be a load/store/delete access.)
        """
        # Locate the name in locals / function / globals scopes.
        if isinstance(node.ctx, (ast.Load, ast.AugLoad)):
            self.handleNodeLoad(node)
            if (node.id == 'locals' and isinstance(self.scope, FunctionScope)
                    and isinstance(node.parent, ast.Call)):
                # we are doing locals() call in current scope
                self.scope.usesLocals = True
        elif isinstance(node.ctx, (ast.Store, ast.AugStore)):
            self.handleNodeStore(node)
        elif isinstance(node.ctx, ast.Del):
            self.handleNodeDelete(node)
        else:
            # must be a Param context -- this only happens for names in function
            # arguments, but these aren't dispatched through here
            raise RuntimeError("Got impossible expression context: %r" % (node.ctx,)) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:21,代码来源:checker.py

示例5: TUPLE

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def TUPLE(self, node):
        if not PY2 and isinstance(node.ctx, ast.Store):
            # Python 3 advanced tuple unpacking: a, *b, c = d.
            # Only one starred expression is allowed, and no more than 1<<8
            # assignments are allowed before a stared expression. There is
            # also a limit of 1<<24 expressions after the starred expression,
            # which is impossible to test due to memory restrictions, but we
            # add it here anyway
            has_starred = False
            star_loc = -1
            for i, n in enumerate(node.elts):
                if isinstance(n, ast.Starred):
                    if has_starred:
                        self.report(messages.TwoStarredExpressions, node)
                        # The SyntaxError doesn't distinguish two from more
                        # than two.
                        break
                    has_starred = True
                    star_loc = i
            if star_loc >= 1 << 8 or len(node.elts) - star_loc - 1 >= 1 << 24:
                self.report(messages.TooManyExpressionsInStarredAssignment, node)
        self.handleChildren(node) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:24,代码来源:checker.py

示例6: visit_Name

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def visit_Name(self, node):
        if isinstance(node.ctx, _ast.Store):
            # this is eqiuvalent to visit_AssName in
            # compiler
            self._add_declared(node.id)
        elif (
            node.id not in reserved
            and node.id not in self.listener.declared_identifiers
            and node.id not in self.local_ident_stack
        ):
            self.listener.undeclared_identifiers.add(node.id) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:13,代码来源:pyparser.py

示例7: visit_Name

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def visit_Name(self, node):
        if isinstance(node.ctx, _ast.Store):
            # this is eqiuvalent to visit_AssName in
            # compiler
            self._add_declared(node.id)
        elif node.id not in reserved and node.id \
            not in self.listener.declared_identifiers and node.id \
                not in self.local_ident_stack:
            self.listener.undeclared_identifiers.add(node.id) 
开发者ID:jpush,项目名称:jbox,代码行数:11,代码来源:pyparser.py

示例8: make_assign_unpack

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def make_assign_unpack(i, bytecode, unpack_num=-1):
    if unpack_num < 1:
      logger.error("Could not find the number of unpacked items. ")
      return i, None

    store_exprs = []
    value_exprs = []
    store_state, value_state = True, False

    while i >= 0:
      op, arg = bytecode[i][2], bytecode[i][3]
      if store_state:
        if op == UNPACK_SEQUENCE:
          store_state = False
          prev_op = bytecode[i - 1][2] if i > 0 else -1
          if prev_op == BUILD_TUPLE:
            value_state = True
          else:
            i, value_exprs = Statement.make_expr(i - 1, bytecode)
            break
        elif op in STORE_OPCODES:
          i, store_stmt = Statement.make_expr(i, bytecode, context=_ast.Store())
          store_exprs.insert(0, store_stmt)
      elif value_state:
        i, value_stmt = Statement.make_expr(i, bytecode)
        value_exprs.insert(0, value_stmt)

      i -= 1

    store_exprs = _ast.Tuple(store_exprs, _ast.Store())
    if not isinstance(value_exprs, _ast.AST):
      value_exprs = _ast.Tuple(value_exprs, _ast.Load())

    return i, _ast.Assign([store_exprs], value_exprs) 
开发者ID:neuroo,项目名称:equip,代码行数:36,代码来源:stmt.py

示例9: make_assign_opt_unpack

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def make_assign_opt_unpack(i, bytecode):
    store_exprs = []
    value_exprs = []
    store_state, value_state = True, False

    while i >= 0:
      op, arg = bytecode[i][2], bytecode[i][3]
      if store_state:
        if op == ROT_TWO:
          prev_op = bytecode[i - 1][2] if i > 0 else -1
          if prev_op == ROT_THREE:
            i -= 1
          value_state = True
          store_state = False
        elif op in STORE_OPCODES:
          i, store_stmt = Statement.make_expr(i, bytecode, context=_ast.Store())
          store_exprs.insert(0, store_stmt)
      elif value_state:
        i, value_stmt = Statement.make_expr(i, bytecode)
        value_exprs.insert(0, value_stmt)
      i -= 1

    store_exprs = _ast.Tuple(store_exprs, _ast.Store())
    if not isinstance(value_exprs, _ast.AST):
      value_exprs = _ast.Tuple(value_exprs, _ast.Load())

    return i, _ast.Assign([store_exprs], value_exprs)


  # Only one case here for:
  #   a = b = z.d.f = foo()
  #    => AST: _ast.Assign(targets=[Tuple(a, b, z.d.f)], value=foo()) 
开发者ID:neuroo,项目名称:equip,代码行数:34,代码来源:stmt.py

示例10: make_exception

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def make_exception(i, bytecode):
    logger.error("Exception STMT not handled.")
    return i, None


  # Store slice has 4 opodes:
  #  (1) STORE_SLICE+0 => TOS[:] = TOS1
  #  (2) STORE_SLICE+1 => TOS1[TOS:] = TOS2
  #  (3) STORE_SLICE+2 => TOS1[:TOS] = TOS2
  #  (4) STORE_SLICE+3 => TOS2[TOS1:TOS] = TOS3 
开发者ID:neuroo,项目名称:equip,代码行数:12,代码来源:stmt.py

示例11: make_store_delete_slice

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def make_store_delete_slice(i, bytecode, context=None):
    op = bytecode[i][2]
    is_delete = op in DELETE_SLICE_OPCODES

    if context is None:
      context = _ast.Store() if not is_delete else _ast.Del()

    lhs_expr = None

    if op in (STORE_SLICE_0, DELETE_SLICE_0):
      i, lhs_expr = Statement.make_expr(i - 1, bytecode, context=context)
      lhs_expr = _ast.Subscript(lhs_expr,
                                _ast.Slice(None, None, None),
                                _ast.Store())
    elif op in (STORE_SLICE_1, STORE_SLICE_2, DELETE_SLICE_1, DELETE_SLICE_2):
      i, index_expr = Statement.make_expr(i - 1, bytecode)
      i, arr_expr = Statement.make_expr(i - 1, bytecode, context=context)

      args = [None] * 3
      index_index = 0 if op in (STORE_SLICE_1, DELETE_SLICE_1) else 1
      args[index_index] = index_expr
      lhs_expr = _ast.Subscript(arr_expr,
                                _ast.Slice(*args),
                                _ast.Store())
    else:
      i, end_index_expr = Statement.make_expr(i - 1, bytecode)
      i, start_index_expr = Statement.make_expr(i - 1, bytecode)
      i, arr_expr = Statement.make_expr(i - 1, bytecode, context=context)

      lhs_expr = _ast.Subscript(arr_expr,
                                _ast.Slice(start_index_expr, end_index_expr, None),
                                _ast.Store())

    if is_delete:
      return i, _ast.Delete([lhs_expr])
    else:
      i, rhs_expr = Statement.make_expr(i - 1, bytecode)
      return i, _ast.Assign([lhs_expr], rhs_expr) 
开发者ID:neuroo,项目名称:equip,代码行数:40,代码来源:stmt.py

示例12: visit_Attribute

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def visit_Attribute( self, node ):
    if isinstance( node.ctx, _ast.Store ):
      if node.attr == self.attr:
        try:
          src,funclineno = inspect.getsourcelines( self.func )
        except IOError:
          # Dynamically generated AST encountered
          # Return null source code and line number as they are not
          # applicable to dynamic AST.
          src, funclineno = '', 0
        lineno         = funclineno + node.lineno - 1
        raise PyMTLError(
          'Cannot write .{attr} in a {kind} block!\n\n'
          ' {lineno} {srccode}\n'
          ' File: {filename}\n'
          ' Function: {funcname}\n'
          ' Line: {lineno}\n'.format(
            attr     = self.attr,
            kind     = {'value':'@tick','next':'@combinational'}[ self.attr ],
            srccode  = src[node.lineno-1],
            filename = inspect.getfile( self.func ),
            funcname = self.func.func_name,
            lineno   = lineno,
          )
        )

#------------------------------------------------------------------------
# DetectMissingValueNext
#------------------------------------------------------------------------ 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:31,代码来源:ast_visitor.py

示例13: visit_Name

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def visit_Name( self, node ):
    if not self.assign: return
    if   isinstance( node.ctx, _ast.Load ):
      self.load  += [ GetVariableName( self ).visit( node ) ]
    elif isinstance( node.ctx, _ast.Store ):
      self.store += [ GetVariableName( self ).visit( node ) ]
    else:
      print( type( node.ctx ) )
      raise Exception( "Unsupported concurrent block code!" ) 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:11,代码来源:ast_visitor.py

示例14: visit_Subscript

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def visit_Subscript( self, node ):
    if not self.assign: return
    if   isinstance( node.ctx, _ast.Load ):
      self.load  += [ GetVariableName( self ).visit( node ) ]
    elif isinstance( node.ctx, _ast.Store ):
      self.store += [ GetVariableName( self ).visit( node ) ]
    else:
      print( type( node.ctx ) )
      raise Exception( "Unsupported concurrent block code!" )

  # TODO: need this to detect writes to bit slices?
  #def visit_Subscript( self, node ):
  #  if not self.assign: return
  #  if   isinstance( node.ctx, _ast.Load ):
  #    self.load  += [ GetVariableName( self ).visit( node ) ]
  #  elif isinstance( node.ctx, _ast.Store ):
  #    self.store += [ GetVariableName( self ).visit( node ) ]
  #  else:
  #    print( type( node.ctx ) )
  #    raise Exception( "Unsupported concurrent block code!" )


#------------------------------------------------------------------------
# GetVariableName
#------------------------------------------------------------------------
# Converts an AST branch, beginning with the indicated node, into it's
# corresponding Python name.  Meant to be called as a utility visitor
# by another AST visitor, which should pass a reference to itself as
# a parameter. 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:31,代码来源:ast_visitor.py

示例15: ANNASSIGN

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Store [as 别名]
def ANNASSIGN(self, node):
        if node.value:
            # Only bind the *targets* if the assignment has a value.
            # Otherwise it's not really ast.Store and shouldn't silence
            # UndefinedLocal warnings.
            self.handleNode(node.target, node)
        self.handleNode(node.annotation, node)
        if node.value:
            # If the assignment has value, handle the *value* now.
            self.handleNode(node.value, node) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:12,代码来源:checker.py


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