Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r61386:1a3dce362e2e Date: 2013-02-17 14:09 -0800 http://bitbucket.org/pypy/pypy/changeset/1a3dce362e2e/
Log: merge upstream diff --git a/lib-python/3.2/ctypes/test/test_arrays.py b/lib-python/3.2/ctypes/test/test_arrays.py --- a/lib-python/3.2/ctypes/test/test_arrays.py +++ b/lib-python/3.2/ctypes/test/test_arrays.py @@ -185,7 +185,7 @@ class T(Array): _type_ = c_int _length_ = sys.maxsize * 2 - with self.assertRaises(AttributeError): + with self.assertRaises((AttributeError, TypeError)): class T(Array): _type_ = c_int _length_ = 1.87 diff --git a/lib-python/3.2/test/test_cmd_line.py b/lib-python/3.2/test/test_cmd_line.py --- a/lib-python/3.2/test/test_cmd_line.py +++ b/lib-python/3.2/test/test_cmd_line.py @@ -8,6 +8,7 @@ import subprocess import tempfile from test.script_helper import spawn_python, kill_python, assert_python_ok, assert_python_failure +from test.support import check_impl_detail # XXX (ncoghlan): Move to script_helper and make consistent with run_python @@ -339,7 +340,8 @@ rc, out, err = assert_python_ok('-R', '-c', code) self.assertEqual(rc, 0) hashes.append(out) - self.assertNotEqual(hashes[0], hashes[1]) + if check_impl_detail(pypy=False): # PyPy does not really implement it! + self.assertNotEqual(hashes[0], hashes[1]) # Verify that sys.flags contains hash_randomization code = 'import sys; print("random is", sys.flags.hash_randomization)' diff --git a/lib-python/3.2/test/test_functools.py b/lib-python/3.2/test/test_functools.py --- a/lib-python/3.2/test/test_functools.py +++ b/lib-python/3.2/test/test_functools.py @@ -47,6 +47,8 @@ # attributes should not be writable if not isinstance(self.thetype, type): return + if not support.check_impl_detail(): + return self.assertRaises(AttributeError, setattr, p, 'func', map) self.assertRaises(AttributeError, setattr, p, 'args', (1, 2)) self.assertRaises(AttributeError, setattr, p, 'keywords', dict(a=1, b=2)) @@ -138,6 +140,7 @@ p = proxy(f) self.assertEqual(f.func, p.func) f = None + support.gc_collect() self.assertRaises(ReferenceError, getattr, p, 'func') def test_with_bound_and_unbound_methods(self): @@ -203,7 +206,7 @@ updated=functools.WRAPPER_UPDATES): # Check attributes were assigned for name in assigned: - self.assertTrue(getattr(wrapper, name) is getattr(wrapped, name)) + self.assertTrue(getattr(wrapper, name) == getattr(wrapped, name)) # Check attributes were updated for name in updated: wrapper_attr = getattr(wrapper, name) diff --git a/lib-python/3.2/test/test_tempfile.py b/lib-python/3.2/test/test_tempfile.py --- a/lib-python/3.2/test/test_tempfile.py +++ b/lib-python/3.2/test/test_tempfile.py @@ -285,6 +285,7 @@ dir = tempfile.mkdtemp() try: self.do_create(dir=dir).write(b"blat") + support.gc_collect() finally: os.rmdir(dir) @@ -575,12 +576,15 @@ self.do_create(suf="b") self.do_create(pre="a", suf="b") self.do_create(pre="aa", suf=".txt") + support.gc_collect() def test_many(self): # mktemp can choose many usable file names (stochastic) extant = list(range(TEST_FILES)) for i in extant: extant[i] = self.do_create(pre="aa") + del extant + support.gc_collect() ## def test_warning(self): ## # mktemp issues a warning when used @@ -1012,6 +1016,7 @@ "TemporaryDirectory %s exists after cleanup" % d1.name) self.assertTrue(os.path.exists(d2.name), "Directory pointed to by a symlink was deleted") + support.gc_collect() self.assertEqual(os.listdir(d2.name), ['test.txt'], "Contents of the directory pointed to by a symlink " "were deleted") diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py --- a/lib_pypy/_ctypes/array.py +++ b/lib_pypy/_ctypes/array.py @@ -8,54 +8,52 @@ class ArrayMeta(_CDataMeta): def __new__(self, name, cls, typedict): res = type.__new__(self, name, cls, typedict) - if '_type_' in typedict: - ffiarray = _rawffi.Array(typedict['_type_']._ffishape) - res._ffiarray = ffiarray - subletter = getattr(typedict['_type_'], '_type_', None) - if subletter == 'c': - def getvalue(self): - return _rawffi.charp2string(self._buffer.buffer, - self._length_) - def setvalue(self, val): - # we don't want to have buffers here - if len(val) > self._length_: - raise ValueError("%r too long" % (val,)) - for i in range(len(val)): - self[i] = val[i] - if len(val) < self._length_: - self[len(val)] = b'\x00' - res.value = property(getvalue, setvalue) + if cls == (_CData,): # this is the Array class defined below + return res - def getraw(self): - return _rawffi.charp2rawstring(self._buffer.buffer, - self._length_) + ffiarray = res._ffiarray = _rawffi.Array(res._type_._ffishape) + subletter = getattr(res._type_, '_type_', None) + if subletter == 'c': + def getvalue(self): + return _rawffi.charp2string(self._buffer.buffer, + self._length_) + def setvalue(self, val): + # we don't want to have buffers here + if len(val) > self._length_: + raise ValueError("%r too long" % (val,)) + for i in range(len(val)): + self[i] = val[i] + if len(val) < self._length_: + self[len(val)] = b'\x00' + res.value = property(getvalue, setvalue) - def setraw(self, buffer): - if len(buffer) > self._length_: - raise ValueError("%r too long" % (buffer,)) - for i in range(len(buffer)): - self[i] = buffer[i] - res.raw = property(getraw, setraw) - elif subletter == 'u': - def getvalue(self): - return _rawffi.wcharp2unicode(self._buffer.buffer, - self._length_) + def getraw(self): + return _rawffi.charp2rawstring(self._buffer.buffer, + self._length_) - def setvalue(self, val): - # we don't want to have buffers here - if len(val) > self._length_: - raise ValueError("%r too long" % (val,)) - for i in range(len(val)): - self[i] = val[i] - if len(val) < self._length_: - self[len(val)] = '\x00' - res.value = property(getvalue, setvalue) - - if '_length_' in typedict: - res._ffishape = (ffiarray, typedict['_length_']) - res._fficompositesize = res._sizeofinstances() - else: - res._ffiarray = None + def setraw(self, buffer): + if len(buffer) > self._length_: + raise ValueError("%r too long" % (buffer,)) + for i in range(len(buffer)): + self[i] = buffer[i] + res.raw = property(getraw, setraw) + elif subletter == 'u': + def getvalue(self): + return _rawffi.wcharp2unicode(self._buffer.buffer, + self._length_) + + def setvalue(self, val): + # we don't want to have buffers here + if len(val) > self._length_: + raise ValueError("%r too long" % (val,)) + for i in range(len(val)): + self[i] = val[i] + if len(val) < self._length_: + self[len(val)] = '\x00' + res.value = property(getvalue, setvalue) + + res._ffishape = (ffiarray, res._length_) + res._fficompositesize = res._sizeofinstances() return res from_address = cdata_from_address diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py --- a/lib_pypy/_ctypes/function.py +++ b/lib_pypy/_ctypes/function.py @@ -556,7 +556,6 @@ try: keepalive, newarg, newargtype = self._conv_param(argtype, args[i]) except (UnicodeError, TypeError, ValueError) as e: - raise raise ArgumentError(str(e)) keepalives.append(keepalive) newargs.append(newarg) diff --git a/lib_pypy/_functools.py b/lib_pypy/_functools.py --- a/lib_pypy/_functools.py +++ b/lib_pypy/_functools.py @@ -1,7 +1,10 @@ """ Supplies the internal functions for functools.py in the standard library """ +from __pypy__ import builtinify + sentinel = object() +@builtinify def reduce(func, sequence, initial=sentinel): """reduce(function, sequence[, initial]) -> value @@ -40,3 +43,17 @@ if self.keywords is not None: fkeywords = dict(self.keywords, **fkeywords) return self.func(*(self.args + fargs), **fkeywords) + + def __repr__(self): + cls = type(self) + if cls is partial: + name = 'functools.partial' + else: + name = cls.__name__ + tmp = [repr(self.func)] + for arg in self.args: + tmp.append(repr(arg)) + if self.keywords: + for k, v in self.keywords.items(): + tmp.append("{}={!r}".format(k, v)) + return "{}({})".format(name, ', '.join(tmp)) diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py --- a/pypy/interpreter/argument.py +++ b/pypy/interpreter/argument.py @@ -508,6 +508,8 @@ plural = "s" if has_kwarg or num_kwds > 0: msg2 = " non-keyword" + elif defcount != -1: # XXX not sure about this + msg2 = " positional" else: msg2 = "" msg = "takes %s %d%s argument%s (%d given)" % ( diff --git a/pypy/interpreter/test/test_argument.py b/pypy/interpreter/test/test_argument.py --- a/pypy/interpreter/test/test_argument.py +++ b/pypy/interpreter/test/test_argument.py @@ -698,3 +698,11 @@ assert e.value.args[0] == "f() got an unexpected keyword argument 'ü'" """ + def test_error_positional(self): + """ + def f(a, b=None, *, c=None): + pass + exc = raises(TypeError, f, 1, 2, 3) + expected = "f() takes at most 2 positional arguments (3 given)" + assert str(exc.value) == expected + """ diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py --- a/pypy/module/_rawffi/interp_rawffi.py +++ b/pypy/module/_rawffi/interp_rawffi.py @@ -55,7 +55,7 @@ return intmask(ffi_type.c_size), intmask(ffi_type.c_alignment) LL_TYPEMAP = { - 'c' : rffi.UCHAR, + 'c' : rffi.CHAR, 'u' : lltype.UniChar, 'b' : rffi.SIGNEDCHAR, 'B' : rffi.UCHAR, @@ -334,7 +334,14 @@ push_func(add_arg, argdesc, rffi.cast(rffi.LONGDOUBLE, space.float_w(w_arg))) elif letter == "c": - val = getbytevalue(space, w_arg) + if space.isinstance_w(w_arg, space.w_int): + val = getbytevalue(space, w_arg) + else: + s = space.str_w(w_arg) + if len(s) != 1: + raise OperationError(space.w_TypeError, w( + "Expected string of length one as character")) + val = s[0] push_func(add_arg, argdesc, val) elif letter == 'u': s = space.unicode_w(w_arg) @@ -363,7 +370,9 @@ if c in TYPEMAP_PTR_LETTERS: res = func(add_arg, argdesc, rffi.VOIDP) return space.wrap(rffi.cast(lltype.Unsigned, res)) - elif c == 'q' or c == 'Q' or c == 'L' or c == 'c' or c == 'u': + elif c == 'c': + return space.wrapbytes(func(add_arg, argdesc, ll_type)) + elif c == 'q' or c == 'Q' or c == 'L' or c == 'u': return space.wrap(func(add_arg, argdesc, ll_type)) elif c == 'f' or c == 'd' or c == 'g': return space.wrap(float(func(add_arg, argdesc, ll_type))) diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py --- a/pypy/module/_rawffi/test/test__rawffi.py +++ b/pypy/module/_rawffi/test/test__rawffi.py @@ -260,7 +260,6 @@ assert lib.ptr(1, [], 'i')()[0] == 42 def test_getchar(self): - py3k_skip('bytes vs unicode') import _rawffi lib = _rawffi.CDLL(self.lib_name) get_char = lib.ptr('get_char', ['P', 'H'], 'c') @@ -272,7 +271,8 @@ intptr = B(1) intptr[0] = i res = get_char(dupaptr, intptr) - assert res[0] == 'dupa'[i:i+1] + char = b'dupa'[i:i+1] + assert res[0] == char intptr.free() dupaptr.free() dupa.free() @@ -282,14 +282,13 @@ import _rawffi A = _rawffi.Array('c') buf = A(10, autofree=True) - buf[0] = ord('*') + buf[0] = b'*' assert buf[1:5] == b'\x00' * 4 buf[7:] = b'abc' - assert buf[9] == ord('c') + assert buf[9] == b'c' assert buf[:8] == b'*' + b'\x00'*6 + b'a' def test_returning_str(self): - py3k_skip('bytes vs unicode') import _rawffi lib = _rawffi.CDLL(self.lib_name) char_check = lib.ptr('char_check', ['c', 'c'], 's') @@ -450,13 +449,13 @@ X = _rawffi.Structure([('x1', 'i'), ('x2', 'h'), ('x3', 'c'), ('next', 'P')]) next = X() next.next = 0 - next.x3 = ord('x') + next.x3 = b'x' x = X() x.next = next x.x1 = 1 x.x2 = 2 - x.x3 = ord('x') - assert X.fromaddress(x.next).x3 == ord('x') + x.x3 = b'x' + assert X.fromaddress(x.next).x3 == b'x' x.free() next.free() create_double_struct = lib.ptr("create_double_struct", [], 'P') @@ -997,15 +996,15 @@ A = _rawffi.Array('c') a = A(10, autofree=True) - a[3] = ord('x') + a[3] = b'x' b = memoryview(a) assert len(b) == 10 assert b[3] == b'x' b[6] = b'y' - assert a[6] == ord('y') + assert a[6] == b'y' b[3:5] = b'zt' - assert a[3] == ord('z') - assert a[4] == ord('t') + assert a[3] == b'z' + assert a[4] == b't' def test_union(self): import _rawffi @@ -1025,6 +1024,18 @@ S2E = _rawffi.Structure([('bah', (EMPTY, 1))]) S2E.get_ffi_type() # does not hang + def test_char_array_int(self): + import _rawffi + A = _rawffi.Array('c') + a = A(1) + a[0] = b'a' + assert a[0] == b'a' + # also accept int but return bytestring + a[0] = 100 + assert a[0] == b'd' + a.free() + + class AppTestAutoFree: spaceconfig = dict(usemodules=['_rawffi', 'struct']) diff --git a/pypy/module/_rawffi/test/test_nested.py b/pypy/module/_rawffi/test/test_nested.py --- a/pypy/module/_rawffi/test/test_nested.py +++ b/pypy/module/_rawffi/test/test_nested.py @@ -43,14 +43,14 @@ assert S.fieldoffset('x') == 0 assert S.fieldoffset('s1') == S1.alignment s = S() - s.x = ord('G') + s.x = b'G' raises(TypeError, 's.s1') assert s.fieldaddress('s1') == s.buffer + S.fieldoffset('s1') s1 = S1.fromaddress(s.fieldaddress('s1')) - s1.c = ord('H') + s1.c = b'H' rawbuf = _rawffi.Array('c').fromaddress(s.buffer, S.size) - assert rawbuf[0] == ord('G') - assert rawbuf[S1.alignment + S1.fieldoffset('c')] == ord('H') + assert rawbuf[0] == b'G' + assert rawbuf[S1.alignment + S1.fieldoffset('c')] == b'H' s.free() def test_array_of_structures(self): @@ -60,17 +60,17 @@ a = A(3) raises(TypeError, "a[0]") s0 = S.fromaddress(a.buffer) - s0.c = ord('B') + s0.c = b'B' assert a.itemaddress(1) == a.buffer + S.size s1 = S.fromaddress(a.itemaddress(1)) - s1.c = ord('A') + s1.c = b'A' s2 = S.fromaddress(a.itemaddress(2)) - s2.c = ord('Z') + s2.c = b'Z' rawbuf = _rawffi.Array('c').fromaddress(a.buffer, S.size * len(a)) ofs = S.fieldoffset('c') - assert rawbuf[0*S.size+ofs] == ord('B') - assert rawbuf[1*S.size+ofs] == ord('A') - assert rawbuf[2*S.size+ofs] == ord('Z') + assert rawbuf[0*S.size+ofs] == b'B' + assert rawbuf[1*S.size+ofs] == b'A' + assert rawbuf[2*S.size+ofs] == b'Z' a.free() def test_array_of_array(self): @@ -103,16 +103,16 @@ assert S.fieldoffset('x') == 0 assert S.fieldoffset('ar') == A5alignment s = S() - s.x = ord('G') + s.x = b'G' raises(TypeError, 's.ar') assert s.fieldaddress('ar') == s.buffer + S.fieldoffset('ar') a1 = A.fromaddress(s.fieldaddress('ar'), 5) a1[4] = 33 rawbuf = _rawffi.Array('c').fromaddress(s.buffer, S.size) - assert rawbuf[0] == ord('G') + assert rawbuf[0] == b'G' sizeofint = struct.calcsize("i") v = 0 for i in range(sizeofint): - v += rawbuf[A5alignment + sizeofint*4+i] + v += ord(rawbuf[A5alignment + sizeofint*4+i]) assert v == 33 s.free() diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py --- a/pypy/objspace/std/floatobject.py +++ b/pypy/objspace/std/floatobject.py @@ -166,7 +166,7 @@ return space.wrap(float2string(w_float.floatval, 'r', 0)) def str__Float(space, w_float): - return space.wrap(float2string(w_float.floatval, 'g', DTSF_STR_PRECISION)) + return space.wrap(float2string(w_float.floatval, 'r', 0)) def format__Float_ANY(space, w_float, w_spec): return newformat.run_formatter(space, w_spec, "format_float", w_float) diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py --- a/pypy/objspace/std/longtype.py +++ b/pypy/objspace/std/longtype.py @@ -48,7 +48,12 @@ bigint = space.bigint_w(w_obj) return newbigint(space, w_longtype, bigint) else: - base = space.int_w(w_base) + try: + base = space.int_w(w_base) + except OperationError, e: + if not e.match(space, space.w_OverflowError): + raise + base = 37 # this raises the right error in string_to_bigint() if space.isinstance_w(w_value, space.w_unicode): from pypy.objspace.std.unicodeobject import unicode_to_decimal_w diff --git a/pypy/objspace/std/test/test_floatobject.py b/pypy/objspace/std/test/test_floatobject.py --- a/pypy/objspace/std/test/test_floatobject.py +++ b/pypy/objspace/std/test/test_floatobject.py @@ -837,3 +837,6 @@ check(mod(0.0, -1.0), -0.0) check(mod(1e-100, -1.0), -1.0) check(mod(1.0, -1.0), -0.0) + + def test_repr_str_eq(self): + assert repr(19 * 0.1) == str(19 * 0.1) diff --git a/pypy/objspace/std/test/test_longobject.py b/pypy/objspace/std/test/test_longobject.py --- a/pypy/objspace/std/test/test_longobject.py +++ b/pypy/objspace/std/test/test_longobject.py @@ -340,3 +340,6 @@ assert 'hello àèìò' in e.message else: assert False, 'did not raise' + + def test_base_overflow(self): + raises(ValueError, int, '42', 2**63) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit