Пример #1
0
 def test_pow_fff(self):
     x = 10.0
     y = 2.0
     z = 13.0
     f1 = W_FloatObject(x)
     f2 = W_FloatObject(y)
     f3 = W_FloatObject(z)
     self.space.raises_w(self.space.w_TypeError, f1.descr_pow, self.space,
                         f2, f3)
Пример #2
0
    def wrap(self, x):
        """ Wraps the Python value 'x' into one of the wrapper classes. This
        should only be used for tests, in real code you need to use the
        explicit new* methods."""
        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):
            return self.newtext(x)
        if isinstance(x, unicode):
            return self.newunicode(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):
            return self.newint(x)

        # we might get there in non-translated versions if 'x' is
        # a long that fits the correct range.
        if is_valid_int(x):
            return self.newint(x)

        return self._wrap_not_rpython(x)
Пример #3
0
 def wrap(self, x):
     """ Wraps the Python value 'x' into one of the wrapper classes. This
     should only be used for tests, in real code you need to use the
     explicit new* methods."""
     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:
             return self._wrap_string_old(x)
         return self.newunicode(unicode_x)
     if isinstance(x, unicode):
         return self.newunicode(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):
         return self.newint(x)
     return self._wrap_not_rpython(x)
Пример #4
0
 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)
Пример #5
0
 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)
Пример #6
0
 def test_pow_ffn(self):
     x = 10.0
     y = 2.0
     f1 = W_FloatObject(x)
     f2 = W_FloatObject(y)
     v = f1.descr_pow(self.space, f2, self.space.w_None)
     assert v.floatval == x**y
     f1 = W_FloatObject(-1.23)
     f2 = W_FloatObject(-4.56)
     self.space.raises_w(self.space.w_ValueError, f1.descr_pow, self.space,
                         f2, self.space.w_None)
     x = -10
     y = 2.0
     f1 = W_FloatObject(x)
     f2 = W_FloatObject(y)
     v = f1.descr_pow(self.space, f2, self.space.w_None)
     assert v.floatval == x**y
Пример #7
0
 def test_pow_ffn(self):
     x = 10.0
     y = 2.0
     f1 = W_FloatObject(x)
     f2 = W_FloatObject(y)
     v = f1.descr_pow(self.space, f2, self.space.w_None)
     assert v.floatval == x**y
     f1 = W_FloatObject(-1.23)
     f2 = W_FloatObject(-4.56)
     v = f1.descr_pow(self.space, f2, self.space.w_None)
     assert self.space.isinstance_w(v, self.space.w_complex)
     x = -10
     y = 2.0
     f1 = W_FloatObject(x)
     f2 = W_FloatObject(y)
     v = f1.descr_pow(self.space, f2, self.space.w_None)
     assert v.floatval == x**y
Пример #8
0
 def newfloat(self, floatval):
     return W_FloatObject(floatval)
Пример #9
0
def unmarshal_Float_bin(space, u, tc):
    return W_FloatObject(unpack_float(u.get(8)))