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


Python ObjSpace.unpackiterable方法代码示例

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


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

示例1: listview

# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
 def listview(self, w_obj, expected_length=-1):
     t = self.listview_no_unpack(w_obj)
     if t is None:
         return ObjSpace.unpackiterable(self, w_obj, expected_length)
     if expected_length != -1 and len(t) != expected_length:
         raise self._wrap_expected_length(expected_length, len(t))
     return t
开发者ID:yuyichao,项目名称:pypy,代码行数:9,代码来源:objspace.py

示例2: unpackiterable

# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
 def unpackiterable(self, w_obj, expected_length=-1):
     if isinstance(w_obj, W_AbstractTupleObject) and self._uses_tuple_iter(w_obj):
         t = w_obj.getitems_copy()
     elif type(w_obj) is W_ListObject:
         t = w_obj.getitems_copy()
     else:
         return ObjSpace.unpackiterable(self, w_obj, expected_length)
     if expected_length != -1 and len(t) != expected_length:
         raise self._wrap_expected_length(expected_length, len(t))
     return t
开发者ID:,项目名称:,代码行数:12,代码来源:

示例3: listview

# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
 def listview(self, w_obj, expected_length=-1):
     if isinstance(w_obj, W_ListObject):
         t = w_obj.wrappeditems
     elif isinstance(w_obj, W_TupleObject):
         t = w_obj.wrappeditems[:]
     else:
         return ObjSpace.unpackiterable(self, w_obj, expected_length)
     if expected_length != -1 and len(t) != expected_length:
         raise self._wrap_expected_length(expected_length, len(t))
     return t
开发者ID:,项目名称:,代码行数:12,代码来源:

示例4: fixedview

# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
 def fixedview(self, w_obj, expected_length=-1, unroll=False):
     """ Fast paths
     """
     if isinstance(w_obj, W_TupleObject):
         t = w_obj.wrappeditems
     elif isinstance(w_obj, W_ListObject):
         t = w_obj.wrappeditems[:]
     else:
         if unroll:
             return make_sure_not_resized(ObjSpace.unpackiterable_unroll(
                 self, w_obj, expected_length)[:])
         else:
             return make_sure_not_resized(ObjSpace.unpackiterable(
                 self, w_obj, expected_length)[:])
     if expected_length != -1 and len(t) != expected_length:
         raise self._wrap_expected_length(expected_length, len(t))
     return make_sure_not_resized(t)
开发者ID:,项目名称:,代码行数:19,代码来源:

示例5: unpackiterable

# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
 def unpackiterable(self, w_iterable, expected_length=None):
     if not isinstance(w_iterable, Variable):
         l = list(self.unwrap(w_iterable))
         if expected_length is not None and len(l) != expected_length:
             raise ValueError
         return [self.wrap(x) for x in l]
     if isinstance(w_iterable, Variable) and expected_length is None:
         raise UnwrapException, ("cannot unpack a Variable iterable" "without knowing its length")
     elif expected_length is not None:
         w_len = self.len(w_iterable)
         w_correct = self.eq(w_len, self.wrap(expected_length))
         if not self.is_true(w_correct):
             e = OperationError(self.w_ValueError, self.w_None)
             e.normalize_exception(self)
             raise e
         return [self.do_operation("getitem", w_iterable, self.wrap(i)) for i in range(expected_length)]
     return ObjSpace.unpackiterable(self, w_iterable, expected_length)
开发者ID:are-prabhu,项目名称:pypy,代码行数:19,代码来源:objspace.py

示例6: fixedview

# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
 def fixedview(self, w_obj, expected_length=-1, unroll=False):
     """ Fast paths
     """
     if isinstance(w_obj, W_AbstractTupleObject) and self._uses_tuple_iter(w_obj):
         t = w_obj.tolist()
     elif type(w_obj) is W_ListObject:
         if unroll:
             t = w_obj.getitems_unroll()
         else:
             t = w_obj.getitems_fixedsize()
     else:
         if unroll:
             return make_sure_not_resized(ObjSpace.unpackiterable_unroll(self, w_obj, expected_length))
         else:
             return make_sure_not_resized(ObjSpace.unpackiterable(self, w_obj, expected_length)[:])
     if expected_length != -1 and len(t) != expected_length:
         raise self._wrap_expected_length(expected_length, len(t))
     return make_sure_not_resized(t)
开发者ID:mozillazg,项目名称:pypy,代码行数:20,代码来源:objspace.py

示例7: unpackiterable

# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
    def unpackiterable(self, w_iterable, expected_length=None):
        if not isinstance(w_iterable, Variable):
            l = list(self.unwrap(w_iterable))
            if expected_length is not None and len(l) != expected_length:
                raise ValueError
            return [self.wrap(x) for x in l]
        if isinstance(w_iterable, Variable) and expected_length is None:
            raise UnwrapException, ("cannot unpack a Variable iterable"
                                    "without knowing its length")
##            # XXX TEMPORARY HACK XXX TEMPORARY HACK XXX TEMPORARY HACK
##            print ("*** cannot unpack a Variable iterable "
##                   "without knowing its length,")
##            print "    assuming a list or tuple with up to 7 items"
##            items = []
##            w_len = self.len(w_iterable)
##            i = 0
##            while True:
##                w_i = self.wrap(i)
##                w_cond = self.eq(w_len, w_i)
##                if self.is_true(w_cond):
##                    break  # done
##                if i == 7:
##                    # too many values
##                    raise OperationError(self.w_AssertionError, self.w_None)
##                w_item = self.do_operation('getitem', w_iterable, w_i)
##                items.append(w_item)
##                i += 1
##            return items
##            # XXX TEMPORARY HACK XXX TEMPORARY HACK XXX TEMPORARY HACK
        elif expected_length is not None:
            w_len = self.len(w_iterable)
            w_correct = self.eq(w_len, self.wrap(expected_length))
            if not self.is_true(w_correct):
                e = OperationError(self.w_ValueError, self.w_None)
                e.normalize_exception(self)
                raise e
            return [self.do_operation('getitem', w_iterable, self.wrap(i)) 
                        for i in range(expected_length)]
        return ObjSpace.unpackiterable(self, w_iterable, expected_length)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:41,代码来源:objspace.py


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