本文整理汇总了Python中pypy.objspace.std.longobject.W_LongObject.fromrarith_int方法的典型用法代码示例。如果您正苦于以下问题:Python W_LongObject.fromrarith_int方法的具体用法?Python W_LongObject.fromrarith_int怎么用?Python W_LongObject.fromrarith_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.objspace.std.longobject.W_LongObject
的用法示例。
在下文中一共展示了W_LongObject.fromrarith_int方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrap
# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromrarith_int [as 别名]
def wrap(self, x):
"Wraps the Python value 'x' into one of the wrapper classes."
# You might notice that this function is rather conspicuously
# not RPython. We can get away with this because the function
# is specialized (see after the function body). Also worth
# noting is that the isinstance's involving integer types
# behave rather differently to how you might expect during
# annotation (see pypy/annotation/builtin.py)
if x is None:
return self.w_None
if isinstance(x, OperationError):
raise TypeError, ("attempt to wrap already wrapped exception: %s"%
(x,))
if isinstance(x, int):
if isinstance(x, bool):
return self.newbool(x)
else:
return self.newint(x)
if isinstance(x, str):
# this hack is temporary: look at the comment in
# test_stdstdobjspace.test_wrap_string
try:
unicode_x = x.decode('ascii')
except UnicodeDecodeError:
# poor man's x.decode('ascii', 'replace'), since it's not
# supported by RPython
if not we_are_translated():
print 'WARNING: space.wrap() called on a non-ascii byte string: %r' % x
lst = []
for ch in x:
ch = ord(ch)
if ch > 127:
lst.append(u'\ufffd')
else:
lst.append(unichr(ch))
unicode_x = u''.join(lst)
return wrapunicode(self, unicode_x)
if isinstance(x, unicode):
return wrapunicode(self, x)
if isinstance(x, float):
return W_FloatObject(x)
if isinstance(x, W_Root):
w_result = x.__spacebind__(self)
#print 'wrapping', x, '->', w_result
return w_result
if isinstance(x, base_int):
if self.config.objspace.std.withsmalllong:
from pypy.objspace.std.smalllongobject import W_SmallLongObject
from rpython.rlib.rarithmetic import r_longlong, r_ulonglong
from rpython.rlib.rarithmetic import longlongmax
if (not isinstance(x, r_ulonglong)
or x <= r_ulonglong(longlongmax)):
return W_SmallLongObject(r_longlong(x))
x = widen(x)
if isinstance(x, int):
return self.newint(x)
else:
return W_LongObject.fromrarith_int(x)
return self._wrap_not_rpython(x)
示例2: wrap
# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromrarith_int [as 别名]
def wrap(self, x):
"Wraps the Python value 'x' into one of the wrapper classes."
# You might notice that this function is rather conspicuously
# not RPython. We can get away with this because the function
# is specialized (see after the function body). Also worth
# noting is that the isinstance's involving integer types
# behave rather differently to how you might expect during
# annotation (see pypy/annotation/builtin.py)
if x is None:
return self.w_None
if isinstance(x, model.W_Object):
raise TypeError, "attempt to wrap already wrapped object: %s"%(x,)
if isinstance(x, OperationError):
raise TypeError, ("attempt to wrap already wrapped exception: %s"%
(x,))
if isinstance(x, int):
if isinstance(x, bool):
return self.newbool(x)
else:
return self.newint(x)
if isinstance(x, str):
return wrapstr(self, x)
if isinstance(x, unicode):
return wrapunicode(self, x)
if isinstance(x, float):
return W_FloatObject(x)
if isinstance(x, Wrappable):
w_result = x.__spacebind__(self)
#print 'wrapping', x, '->', w_result
return w_result
if isinstance(x, base_int):
if self.config.objspace.std.withsmalllong:
from pypy.objspace.std.smalllongobject import W_SmallLongObject
from pypy.rlib.rarithmetic import r_longlong, r_ulonglong
from pypy.rlib.rarithmetic import longlongmax
if (not isinstance(x, r_ulonglong)
or x <= r_ulonglong(longlongmax)):
return W_SmallLongObject(r_longlong(x))
x = widen(x)
if isinstance(x, int):
return self.newint(x)
else:
return W_LongObject.fromrarith_int(x)
return self._wrap_not_rpython(x)
示例3: newlong_from_rarith_int
# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromrarith_int [as 别名]
def newlong_from_rarith_int(self, val): # val is an rarithmetic type
return W_LongObject.fromrarith_int(val)