本文整理汇总了Python中pypy.objspace.std.longobject.W_LongObject.fromlong方法的典型用法代码示例。如果您正苦于以下问题:Python W_LongObject.fromlong方法的具体用法?Python W_LongObject.fromlong怎么用?Python W_LongObject.fromlong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.objspace.std.longobject.W_LongObject
的用法示例。
在下文中一共展示了W_LongObject.fromlong方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wraplong
# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromlong [as 别名]
def wraplong(self, x):
"NOT_RPYTHON"
if self.config.objspace.std.withsmalllong:
from rpython.rlib.rarithmetic import r_longlong
try:
rx = r_longlong(x)
except OverflowError:
pass
else:
from pypy.objspace.std.smalllongobject import \
W_SmallLongObject
return W_SmallLongObject(rx)
return W_LongObject.fromlong(x)
示例2: _wrap_not_rpython
# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromlong [as 别名]
def _wrap_not_rpython(self, x):
"NOT_RPYTHON"
# _____ this code is here to support testing only _____
# wrap() of a container works on CPython, but the code is
# not RPython. Don't use -- it is kept around mostly for tests.
# Use instead newdict(), newlist(), newtuple().
if isinstance(x, dict):
items_w = [(self.wrap(k), self.wrap(v)) for (k, v) in x.iteritems()]
r = self.newdict()
r.initialize_content(items_w)
return r
if isinstance(x, tuple):
wrappeditems = [self.wrap(item) for item in list(x)]
return self.newtuple(wrappeditems)
if isinstance(x, list):
wrappeditems = [self.wrap(item) for item in x]
return self.newlist(wrappeditems)
# The following cases are even stranger.
# Really really only for tests.
if type(x) is long:
if self.config.objspace.std.withsmalllong:
from pypy.rlib.rarithmetic import r_longlong
try:
rx = r_longlong(x)
except OverflowError:
pass
else:
from pypy.objspace.std.smalllongobject import \
W_SmallLongObject
return W_SmallLongObject(rx)
return W_LongObject.fromlong(x)
if isinstance(x, slice):
return W_SliceObject(self.wrap(x.start),
self.wrap(x.stop),
self.wrap(x.step))
if isinstance(x, complex):
return W_ComplexObject(x.real, x.imag)
if isinstance(x, set):
rdict_w = r_dict(self.eq_w, self.hash_w)
for item in x:
rdict_w[self.wrap(item)] = None
res = W_SetObject(self, rdict_w)
return res
if isinstance(x, frozenset):
wrappeditems = [self.wrap(item) for item in x]
return W_FrozensetObject(self, wrappeditems)
if x is __builtin__.Ellipsis:
# '__builtin__.Ellipsis' avoids confusion with special.Ellipsis
return self.w_Ellipsis
if self.config.objspace.nofaking:
raise OperationError(self.w_RuntimeError,
self.wrap("nofaking enabled: refusing "
"to wrap cpython value %r" %(x,)))
if isinstance(x, type(Exception)) and issubclass(x, Exception):
w_result = self.wrap_exception_cls(x)
if w_result is not None:
return w_result
from pypy.objspace.std.fake import fake_object
return fake_object(self, x)