Author: Armin Rigo <ar...@tunes.org> Branch: fix-strbuf Changeset: r78666:f1ee691d79af Date: 2015-07-26 12:32 +0200 http://bitbucket.org/pypy/pypy/changeset/f1ee691d79af/
Log: (fijal, arigo) Move these three methods to W_AbstractBytesObject, with test 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 @@ -424,6 +424,21 @@ of the specified width. The string S is never truncated. """ + def writebuf_w(self, space): + raise OperationError(space.w_TypeError, space.wrap( + "Cannot use string as modifiable buffer")) + + def charbuf_w(self, space): + return self.str_w(space) + + def ord(self, space): + value = self.str_w(space) + if len(value) != 1: + raise oefmt(space.w_TypeError, + "ord() expected a character, but string of length %d " + "found", len(value)) + return space.wrap(ord(value[0])) + class W_BytesObject(W_AbstractBytesObject): import_from_mixin(StringMethods) @@ -450,22 +465,9 @@ def readbuf_w(self, space): return StringBuffer(self._value) - def writebuf_w(self, space): - raise OperationError(space.w_TypeError, space.wrap( - "Cannot use string as modifiable buffer")) - - charbuf_w = str_w - def listview_bytes(self): return _create_list_from_bytes(self._value) - def ord(self, space): - if len(self._value) != 1: - raise oefmt(space.w_TypeError, - "ord() expected a character, but string of length %d " - "found", len(self._value)) - return space.wrap(ord(self._value[0])) - def _new(self, value): return W_BytesObject(value) diff --git a/pypy/objspace/std/test/test_strbufobject.py b/pypy/objspace/std/test/test_strbufobject.py --- a/pypy/objspace/std/test/test_strbufobject.py +++ b/pypy/objspace/std/test/test_strbufobject.py @@ -89,3 +89,8 @@ a += 'b' assert 'foo%s' % a == 'fooab' assert (a + '%s') % ('foo',) == 'abfoo' + + def test_print(self): + a = 'abc' + a += 'bc' + print a _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit