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


Python _ast.Tuple方法代码示例

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


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

示例1: make_assign_chained

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [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

示例2: convert_to_value

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def convert_to_value(item):
    if isinstance(item, ast.Str):
        return item.s
    elif hasattr(ast, 'Bytes') and isinstance(item, ast.Bytes):
        return item.s
    elif isinstance(item, ast.Tuple):
        return tuple(convert_to_value(i) for i in item.elts)
    elif isinstance(item, ast.Num):
        return item.n
    elif isinstance(item, ast.Name):
        result = VariableKey(item=item)
        constants_lookup = {
            'True': True,
            'False': False,
            'None': None,
        }
        return constants_lookup.get(
            result.name,
            result,
        )
    elif (not PY33) and isinstance(item, ast.NameConstant):
        # None, True, False are nameconstants in python3, but names in 2
        return item.value
    else:
        return UnhandledKeyType() 
开发者ID:zrzka,项目名称:blackmamba,代码行数:27,代码来源:checker.py

示例3: TRY

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def TRY(self, node):
        handler_names = []
        # List the exception handlers
        for i, handler in enumerate(node.handlers):
            if isinstance(handler.type, ast.Tuple):
                for exc_type in handler.type.elts:
                    handler_names.append(getNodeName(exc_type))
            elif handler.type:
                handler_names.append(getNodeName(handler.type))

            if handler.type is None and i < len(node.handlers) - 1:
                self.report(messages.DefaultExceptNotLast, handler)
        # Memorize the except handlers and process the body
        self.exceptHandlers.append(handler_names)
        for child in node.body:
            self.handleNode(child, node)
        self.exceptHandlers.pop()
        # Process the other nodes: "except:", "else:", "finally:"
        self.handleChildren(node, omit='body') 
开发者ID:zrzka,项目名称:blackmamba,代码行数:21,代码来源:checker.py

示例4: TRY

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def TRY(self, node):
        handler_names = []
        # List the exception handlers
        for handler in node.handlers:
            if isinstance(handler.type, ast.Tuple):
                for exc_type in handler.type.elts:
                    handler_names.append(getNodeName(exc_type))
            elif handler.type:
                handler_names.append(getNodeName(handler.type))
        # Memorize the except handlers and process the body
        self.exceptHandlers.append(handler_names)
        for child in node.body:
            self.handleNode(child, node)
        self.exceptHandlers.pop()
        # Process the other nodes: "except:", "else:", "finally:"
        self.handleChildren(node, omit='body') 
开发者ID:QQuick,项目名称:Transcrypt,代码行数:18,代码来源:checker.py

示例5: _expand_tuples

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def _expand_tuples(self, args):
        for arg in args:
            if isinstance(arg, _ast.Tuple):
                for n in arg.elts:
                    yield n
            else:
                yield arg 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:pyparser.py

示例6: make_assign_unpack

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [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

示例7: make_assign_opt_unpack

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [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

示例8: make_tuple_list

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def make_tuple_list(i, bytecode):
    op, arg = bytecode[i][2], bytecode[i][3]
    pop, push = get_stack_effect(op, arg)
    values = []
    for k in range(pop):
      i, expr = Statement.make_expr(i - 1, bytecode)
      values.insert(0, expr)
    cls = _ast.Tuple if op == BUILD_TUPLE else _ast.List
    return i, cls(values, _ast.Load()) 
开发者ID:neuroo,项目名称:equip,代码行数:11,代码来源:stmt.py

示例9: sequence_typeof

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def sequence_typeof(ast_node):
  if isinstance(ast_node, _ast.Str):
    return StringType()
  elif isinstance(ast_node, _ast.Tuple):
    return TupleType()
  elif isinstance(ast_node, _ast.List):
    return ListType()

  return SequenceType() 
开发者ID:neuroo,项目名称:equip,代码行数:11,代码来源:types.py

示例10: is_sequence

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def is_sequence(ast_node):
  return isinstance(ast_node, _ast.Str)   \
      or isinstance(ast_node, _ast.Tuple) \
      or isinstance(ast_node, _ast.List) 
开发者ID:neuroo,项目名称:equip,代码行数:6,代码来源:types.py

示例11: assign

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def assign(self, node, val):
        cls = node.__class__

        if cls == _ast.Name:
            self.symbol_table[node.id] = val
        elif cls in (_ast.Tuple, _ast.List):
            if not isinstance(val, abc.Iterable):
                raise TypeError(
                    'cannot unpack non-iterable {} object'.format(
                        type(val).__name__,
                    )
                )
            for telem, tval in itertools.zip_longest(
                node.elts, val, fillvalue=PLACEHOLDER,
            ):
                if telem == PLACEHOLDER:
                    raise ValueError('not enough values to unpack')
                if tval == PLACEHOLDER:
                    raise ValueError('too many values to unpack')
                self.assign(telem, tval)
        elif cls == _ast.Subscript:
            sym = self._run(node.value)
            xslice = self._run(node.slice)
            if isinstance(node.slice, _ast.Index):
                sym[xslice] = val
            elif isinstance(node.slice, _ast.Slice):
                sym[slice(xslice.start, xslice.stop)] = val
            elif isinstance(node.slice, _ast.ExtSlice):
                sym[xslice] = val
        else:
            raise BadSyntax('This assign method is not allowed') 
开发者ID:item4,项目名称:yui,代码行数:33,代码来源:calc.py

示例12: delete

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def delete(self, node):
        cls = node.__class__

        if cls == _ast.Name:
            del self.symbol_table[node.id]
        elif cls == _ast.Tuple:
            for elt in node.elts:
                self.delete(elt) 
开发者ID:item4,项目名称:yui,代码行数:10,代码来源:calc.py

示例13: visit_tuple

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def visit_tuple(self, node: _ast.Tuple):  # elts, ctx
        return tuple(self._run(x) for x in node.elts) 
开发者ID:item4,项目名称:yui,代码行数:4,代码来源:calc.py

示例14: __init__

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def __init__(self, name, source, scope):
        if '__all__' in scope and isinstance(source, ast.AugAssign):
            self.names = list(scope['__all__'].names)
        else:
            self.names = []
        if isinstance(source.value, (ast.List, ast.Tuple)):
            for node in source.value.elts:
                if isinstance(node, ast.Str):
                    self.names.append(node.s)
        super(ExportBinding, self).__init__(name, source) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:12,代码来源:checker.py

示例15: getParent

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Tuple [as 别名]
def getParent(self, node):
        # Lookup the first parent which is not Tuple, List or Starred
        while True:
            node = node.parent
            if not hasattr(node, 'elts') and not hasattr(node, 'ctx'):
                return node 
开发者ID:zrzka,项目名称:blackmamba,代码行数:8,代码来源:checker.py


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