Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r87867:85ace3e772f4 Date: 2016-10-18 21:29 +0200 http://bitbucket.org/pypy/pypy/changeset/85ace3e772f4/
Log: hg merge default diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py --- a/pypy/module/cpyext/pyerrors.py +++ b/pypy/module/cpyext/pyerrors.py @@ -21,7 +21,7 @@ @cpython_api([PyObject, CONST_STRING], lltype.Void) def PyErr_SetString(space, w_type, message_ptr): message = rffi.charp2str(message_ptr) - PyErr_SetObject(space, w_type, space.newbytes(message)) + PyErr_SetObject(space, w_type, space.wrap(message)) @cpython_api([PyObject], lltype.Void, error=CANNOT_FAIL) def PyErr_SetNone(space, w_type): @@ -147,7 +147,7 @@ # XXX Doesn't actually do anything with PyErr_CheckSignals. if llfilename: filename = rffi.charp2str(llfilename) - w_filename = space.newbytes(filename) + w_filename = space.wrap(filename) else: w_filename = space.w_None @@ -166,13 +166,13 @@ msg = _strerror(errno) if w_value: w_error = space.call_function(w_type, - space.newint(errno), - space.newbytes(msg), + space.wrap(errno), + space.wrap(msg), w_value) else: w_error = space.call_function(w_type, - space.newint(errno), - space.newbytes(msg)) + space.wrap(errno), + space.wrap(msg)) raise OperationError(w_type, w_error) @cpython_api([], rffi.INT_real, error=-1) @@ -250,11 +250,11 @@ documentation. There is no C API for warning control.""" if w_category is None: w_category = space.w_None - w_message = space.newbytes(rffi.charp2str(message_ptr)) - w_stacklevel = space.newint(rffi.cast(lltype.Signed, stacklevel)) + w_message = space.wrap(rffi.charp2str(message_ptr)) + w_stacklevel = space.wrap(rffi.cast(lltype.Signed, stacklevel)) - w_module = PyImport_Import(space, space.newbytes("warnings")) - w_warn = space.getattr(w_module, space.newbytes("warn")) + w_module = PyImport_Import(space, space.wrap("warnings")) + w_warn = space.getattr(w_module, space.wrap("warn")) space.call_function(w_warn, w_message, w_category, w_stacklevel) return 0 @@ -315,10 +315,10 @@ @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1) def PyTraceBack_Print(space, w_tb, w_file): - space.call_method(w_file, "write", space.newbytes( + space.call_method(w_file, "write", space.wrap( 'Traceback (most recent call last):\n')) w_traceback = space.call_method(space.builtin, '__import__', - space.newbytes("traceback")) + space.wrap("traceback")) space.call_method(w_traceback, "print_tb", w_tb, space.w_None, w_file) return 0 diff --git a/pypy/module/cpyext/test/test_memoryobject.py b/pypy/module/cpyext/test/test_memoryobject.py --- a/pypy/module/cpyext/test/test_memoryobject.py +++ b/pypy/module/cpyext/test/test_memoryobject.py @@ -8,7 +8,6 @@ only_pypy ="config.option.runappdirect and '__pypy__' not in sys.builtin_module_names" class TestMemoryViewObject(BaseApiTest): - skip('needs c_bf_getbuffer wrapper from slotdefs') def test_fromobject(self, space, api): w_hello = space.newbytes("hello") assert api.PyObject_CheckBuffer(w_hello) diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py --- a/pypy/objspace/std/bytesobject.py +++ b/pypy/objspace/std/bytesobject.py @@ -672,6 +672,9 @@ def descr_mod(self, space, w_values): return mod_format(space, self, w_values, fmt_type=FORMAT_BYTES) + def descr_rmod(self, space, w_values): + return mod_format(space, w_values, self, fmt_type=FORMAT_BYTES) + @staticmethod def _iter_getitem_result(self, space, index): assert isinstance(self, W_BytesObject) @@ -809,6 +812,7 @@ __rmul__ = interpindirect2app(W_AbstractBytesObject.descr_rmul), __mod__ = interpindirect2app(W_AbstractBytesObject.descr_mod), + __rmod__ = interpindirect2app(W_AbstractBytesObject.descr_rmod), __getitem__ = interpindirect2app(W_AbstractBytesObject.descr_getitem), diff --git a/pypy/objspace/std/test/test_bytesobject.py b/pypy/objspace/std/test/test_bytesobject.py --- a/pypy/objspace/std/test/test_bytesobject.py +++ b/pypy/objspace/std/test/test_bytesobject.py @@ -106,11 +106,43 @@ raises(TypeError, bytes.fromhex, True) raises(ValueError, bytes.fromhex, "hello world") + def test_format(self): + raises(TypeError, "foo".__mod__, "bar") + raises(TypeError, u"foo".__mod__, "bar") + raises(TypeError, "foo".__mod__, u"bar") + + for format, arg, cls in [("a %s b", "foo", str), + (u"a %s b", "foo", unicode), + ("a %s b", u"foo", unicode), + (u"a %s b", u"foo", unicode)]: + raises(TypeError, format[:2].__mod__, arg) + result = format % arg + assert result == "a foo b" + assert isinstance(result, cls) + + + for format, arg, cls in [("a %s b", "foo", str), + (u"a %s b", u"foo", unicode)]: + raises(TypeError, arg.__rmod__, format[:2]) + result = arg.__rmod__(format) + assert result == "a foo b" + assert isinstance(result, cls) + for format, arg, cls in [(u"a %s b", "foo", str), + ("a %s b", u"foo", unicode)]: + result = arg.__rmod__(format) + if '__pypy__' in sys.builtin_module_names: + raises(TypeError, arg.__rmod__, format[:2]) + assert result == "a foo b" + assert isinstance(result, cls) + else: + assert result is NotImplemented + def test_format_wrongtype(self): for int_format in '%d', '%o', '%x': exc_info = raises(TypeError, int_format.__mod__, '123') expected = int_format + ' format: a number is required, not str' assert str(exc_info.value) == expected + raises(TypeError, "None % 'abc'") # __rmod__ def test_split(self): assert b"".split() == [] @@ -822,6 +854,10 @@ raises(TypeError, len, iter(iterable)) def test___radd__(self): + raises(TypeError, "None + ''") + raises(AttributeError, "'abc'.__radd__('def')") + + class Foo(object): def __radd__(self, other): return 42 diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py --- a/pypy/objspace/std/test/test_unicodeobject.py +++ b/pypy/objspace/std/test/test_unicodeobject.py @@ -740,9 +740,9 @@ def test_call_special_methods(self): # xxx not completely clear if these are implementation details or not assert 'abc'.__add__('def') == 'abcdef' - assert 'abc'.__add__('def') == 'abcdef' - assert 'abc'.__add__('def') == 'abcdef' - # xxx CPython has no str.__radd__ and no unicode.__radd__ + assert u'abc'.__rmod__(u'%s') == u'abc' + ret = u'abc'.__rmod__('%s') + raises(AttributeError, "u'abc'.__radd__(u'def')") def test_str_unicode_concat_overrides(self): "Test from Jython about being bug-compatible with CPython." diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -405,6 +405,9 @@ def descr_mod(self, space, w_values): return mod_format(space, self, w_values, fmt_type=FORMAT_UNICODE) + def descr_rmod(self, space, w_values): + return mod_format(space, w_values, self, fmt_type=FORMAT_UNICODE) + def descr_translate(self, space, w_table): selfvalue = self._value w_sys = space.getbuiltinmodule('sys') @@ -750,6 +753,9 @@ def __mod__(): """x.__mod__(y) <==> x%y""" + def __rmod__(): + """x.__rmod__(y) <==> y%x""" + def __mul__(): """x.__mul__(n) <==> x*n""" @@ -1261,6 +1267,8 @@ doc=UnicodeDocstrings.__format__.__doc__), __mod__ = interp2app(W_UnicodeObject.descr_mod, doc=UnicodeDocstrings.__mod__.__doc__), + __rmod__ = interp2app(W_UnicodeObject.descr_rmod, + doc=UnicodeDocstrings.__rmod__.__doc__), __getnewargs__ = interp2app(W_UnicodeObject.descr_getnewargs, doc=UnicodeDocstrings.__getnewargs__.__doc__), maketrans = interp2app(W_UnicodeObject.descr_maketrans, diff --git a/rpython/rlib/rtime.py b/rpython/rlib/rtime.py --- a/rpython/rlib/rtime.py +++ b/rpython/rlib/rtime.py @@ -29,7 +29,8 @@ 'sys/types.h', 'unistd.h', 'sys/time.h', 'sys/resource.h'] - if not sys.platform.startswith("openbsd"): + if not sys.platform.startswith("openbsd") and \ + not sys.platform.startswith("freebsd"): includes.append('sys/timeb.h') need_rusage = True _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit