Author: Brian Kearns <bdkea...@gmail.com> Branch: refactor-buffer-api Changeset: r70927:1b961b9e0f74 Date: 2014-04-24 04:29 -0400 http://bitbucket.org/pypy/pypy/changeset/1b961b9e0f74/
Log: simplify buffer.readonly/is_writable() diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py --- a/pypy/module/micronumpy/ndarray.py +++ b/pypy/module/micronumpy/ndarray.py @@ -1218,7 +1218,7 @@ return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype, w_subtype=w_subtype, w_base=w_buffer, - writable=buf.is_writable()) + writable=not buf.readonly) order = order_converter(space, w_order, NPY.CORDER) if order == NPY.CORDER: diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py --- a/pypy/objspace/std/bufferobject.py +++ b/pypy/objspace/std/bufferobject.py @@ -61,7 +61,7 @@ return space.wrap(res) def descr_setitem(self, space, w_index, w_obj): - if not self.buf.is_writable(): + if self.buf.readonly: raise OperationError(space.w_TypeError, space.wrap("buffer is read-only")) start, stop, step, size = space.decode_index4(w_index, self.buf.getlength()) @@ -117,10 +117,10 @@ return space.call_method(w_string, '__mul__', w_times) def descr_repr(self, space): - if self.buf.is_writable(): + if self.buf.readonly: + info = 'read-only buffer' + else: info = 'read-write buffer' - else: - info = 'read-only buffer' addrstring = self.getaddrstring(space) return space.wrap("<%s for 0x%s, size %d>" % diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -91,7 +91,7 @@ return space.wrap(res) def descr_setitem(self, space, w_index, w_obj): - if not self.buf.is_writable(): + if self.buf.readonly: raise OperationError(space.w_TypeError, space.wrap( "cannot modify read-only memory")) start, stop, step, size = space.decode_index4(w_index, self.buf.getlength()) @@ -119,7 +119,7 @@ return space.wrap(1) def w_is_readonly(self, space): - return space.wrap(not self.buf.is_writable()) + return space.wrap(self.buf.readonly) def w_get_shape(self, space): return space.newtuple([space.wrap(self.getlength())]) diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py --- a/rpython/rlib/buffer.py +++ b/rpython/rlib/buffer.py @@ -37,9 +37,6 @@ def get_raw_address(self): raise ValueError("no raw buffer") - def is_writable(self): - return not self.readonly - class StringBuffer(Buffer): __slots__ = ['value'] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit