def newbigint(space, w_longtype, bigint): """Turn the bigint into a W_LongObject. If withsmalllong is enabled, check if the bigint would fit in a smalllong, and return a W_SmallLongObject instead if it does. Similar to newlong() in longobject.py, but takes an explicit w_longtype argument. """ if (space.config.objspace.std.withsmalllong and space.is_w(w_longtype, space.w_long)): try: z = bigint.tolonglong() except OverflowError: pass else: from pypy.objspace.std.smalllongobject import W_SmallLongObject return W_SmallLongObject(z) from pypy.objspace.std.longobject import W_LongObject w_obj = space.allocate_instance(W_LongObject, w_longtype) W_LongObject.__init__(w_obj, bigint) return w_obj
s = unicode_to_decimal_w(space, w_value) else: try: s = space.str_w(w_value) except OperationError, e: raise OperationError(space.w_TypeError, space.wrap("long() can't convert non-string " "with explicit base")) try: w_value = string_to_w_long(space, s, base) except ParseStringError, e: raise OperationError(space.w_ValueError, space.wrap(e.msg)) w_obj = space.allocate_instance(W_LongObject, w_longtype) W_LongObject.__init__(w_obj, w_value.num) return w_obj # ____________________________________________________________ long_typedef = StdTypeDef("long", __doc__ = '''long(x[, base]) -> integer Convert a string or number to a long integer, if possible. A floating point argument will be truncated towards zero (this does not include a string representation of a floating point number!) When converting a string, use the optional base. It is an error to supply a base when converting a non-string.''', __new__ = newmethod(descr__new__), )