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