[pypy-commit] pypy py3k: kill off old buffer interface and its usage
bdkearns
noreply at buildbot.pypy.org
Sun May 4 00:35:45 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: py3k
Changeset: r71246:7bcdbe1b48bd
Date: 2014-05-03 18:35 -0400
http://bitbucket.org/pypy/pypy/changeset/7bcdbe1b48bd/
Log: kill off old buffer interface and its usage
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -202,30 +202,6 @@
return w_result.buffer_w(space, flags)
raise TypeError
- def readbuf_w(self, space):
- w_impl = space.lookup(self, '__buffer__')
- if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
- if space.isinstance_w(w_result, space.w_memoryview):
- return w_result.readbuf_w(space)
- return self.buffer_w(space, space.BUF_SIMPLE)
-
- def writebuf_w(self, space):
- w_impl = space.lookup(self, '__buffer__')
- if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
- if space.isinstance_w(w_result, space.w_memoryview):
- return w_result.writebuf_w(space)
- return self.buffer_w(space, space.BUF_WRITABLE)
-
- def charbuf_w(self, space):
- w_impl = space.lookup(self, '__buffer__')
- if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
- if space.isinstance_w(w_result, space.w_memoryview):
- return w_result.charbuf_w(space)
- return self.buffer_w(space, space.BUF_SIMPLE).as_str()
-
def bytes_w(self, space):
self._typed_unwrap_error(space, "bytes")
@@ -1373,31 +1349,33 @@
return w_obj.buffer_w(self, flags)
except TypeError:
raise oefmt(self.w_TypeError,
- "'%T' does not have the buffer interface", w_obj)
+ "'%T' does not support the buffer interface", w_obj)
def readbuf_w(self, w_obj):
# Old buffer interface, returns a readonly buffer (PyObject_AsReadBuffer)
try:
- return w_obj.readbuf_w(self)
+ return w_obj.buffer_w(self, self.BUF_SIMPLE)
except TypeError:
raise oefmt(self.w_TypeError,
- "expected a readable buffer object")
+ "expected an object with a buffer interface")
def writebuf_w(self, w_obj):
# Old buffer interface, returns a writeable buffer (PyObject_AsWriteBuffer)
try:
- return w_obj.writebuf_w(self)
+ return w_obj.buffer_w(self, self.BUF_WRITABLE)
except TypeError:
raise oefmt(self.w_TypeError,
- "expected a writeable buffer object")
+ "expected an object with a writable buffer interface")
def charbuf_w(self, w_obj):
# Old buffer interface, returns a character buffer (PyObject_AsCharBuffer)
try:
- return w_obj.charbuf_w(self)
+ buf = w_obj.buffer_w(self, self.BUF_SIMPLE)
except TypeError:
raise oefmt(self.w_TypeError,
- "expected a character buffer object")
+ "expected an object with a buffer interface")
+ else:
+ return buf.as_str()
def _getarg_error(self, expected, w_obj):
if self.is_none(w_obj):
@@ -1414,15 +1392,11 @@
code = 's*'
if code == 's*':
if self.isinstance_w(w_obj, self.w_str):
- return w_obj.readbuf_w(self)
+ return StringBuffer(w_obj.bytes_w)
if self.isinstance_w(w_obj, self.w_unicode):
return StringBuffer(w_obj.identifier_w(self))
try:
- return w_obj.buffer_w(self, 0)
- except TypeError:
- pass
- try:
- return w_obj.readbuf_w(self)
+ return w_obj.buffer_w(self, self.BUF_SIMPLE)
except TypeError:
self._getarg_error("bytes or buffer", w_obj)
elif code == 's#':
@@ -1431,7 +1405,7 @@
if self.isinstance_w(w_obj, self.w_unicode):
return w_obj.identifier_w(self)
try:
- return w_obj.readbuf_w(self).as_str()
+ return w_obj.buffer_w(self, self.BUF_SIMPLE).as_str()
except TypeError:
self._getarg_error("bytes or read-only buffer", w_obj)
elif code == 'w*':
@@ -1439,13 +1413,10 @@
try:
return w_obj.buffer_w(self, self.BUF_WRITABLE)
except OperationError:
- self._getarg_error("read-write buffer", w_obj)
+ pass
except TypeError:
pass
- try:
- return w_obj.writebuf_w(self)
- except TypeError:
- self._getarg_error("read-write buffer", w_obj)
+ self._getarg_error("read-write buffer", w_obj)
else:
assert False
@@ -1467,12 +1438,6 @@
try:
buf = w_obj.buffer_w(self, 0)
except TypeError:
- pass
- else:
- return buf.as_str()
- try:
- buf = w_obj.readbuf_w(self)
- except TypeError:
raise oefmt(self.w_TypeError,
"'%T' does not support the buffer interface", w_obj)
else:
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
@@ -363,12 +363,6 @@
def buffer_w(self, space, flags):
return RawFFIBuffer(self)
- def readbuf_w(self, space):
- return RawFFIBuffer(self)
-
- def writebuf_w(self, space):
- return RawFFIBuffer(self)
-
def getrawsize(self):
raise NotImplementedError("abstract base class")
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -141,12 +141,6 @@
def buffer_w(self, space, flags):
return ArrayBuffer(self, False)
- def readbuf_w(self, space):
- return ArrayBuffer(self, True)
-
- def writebuf_w(self, space):
- return ArrayBuffer(self, False)
-
def descr_append(self, space, w_x):
""" append(x)
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -340,12 +340,6 @@
def buffer_w(self, space, flags):
return self.descr_ravel(space).buffer_w(space, flags)
- def readbuf_w(self, space):
- return self.descr_ravel(space).readbuf_w(space)
-
- def charbuf_w(self, space):
- return self.descr_ravel(space).charbuf_w(space)
-
def descr_byteswap(self, space):
return self.get_dtype(space).itemtype.byteswap(self)
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
@@ -621,15 +621,6 @@
def buffer_w(self, space, flags):
return self.implementation.get_buffer(space, True)
- def readbuf_w(self, space):
- return self.implementation.get_buffer(space, True)
-
- def writebuf_w(self, space):
- return self.implementation.get_buffer(space, False)
-
- def charbuf_w(self, space):
- return self.implementation.get_buffer(space, True).as_str()
-
def descr_get_data(self, space):
return space.newbuffer(self.implementation.get_buffer(space, False))
diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py
--- a/pypy/module/mmap/interp_mmap.py
+++ b/pypy/module/mmap/interp_mmap.py
@@ -17,9 +17,9 @@
self.space = space
self.mmap = mmap_obj
- def readbuf_w(self, space):
+ def buffer_w(self, space, flags):
self.check_valid()
- return MMapBuffer(self.space, self.mmap, True)
+ return MMapBuffer(self.space, self.mmap, flags & space.BUF_WRITABLE)
def close(self):
self.mmap.close()
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -31,15 +31,6 @@
def buffer_w(self, space, flags):
return BytearrayBuffer(self.data, False)
- def readbuf_w(self, space):
- return BytearrayBuffer(self.data, True)
-
- def writebuf_w(self, space):
- return BytearrayBuffer(self.data, False)
-
- def charbuf_w(self, space):
- return ''.join(self.data)
-
def _new(self, value):
return W_BytearrayObject(_make_data(value))
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
@@ -402,13 +402,6 @@
space.check_buf_flags(flags, True)
return StringBuffer(self._value)
- 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"))
-
def listview_int(self):
return _create_list_from_bytes(self._value)
@@ -440,7 +433,7 @@
except OperationError, e:
if not e.match(space, space.w_TypeError):
raise
- return space.charbuf_w(w_other)
+ return space.buffer_w(w_other, space.BUF_SIMPLE).as_str()
def _chr(self, char):
assert len(char) == 1
diff --git a/pypy/objspace/std/strbufobject.py b/pypy/objspace/std/strbufobject.py
--- a/pypy/objspace/std/strbufobject.py
+++ b/pypy/objspace/std/strbufobject.py
@@ -39,9 +39,6 @@
def buffer_w(self, space, flags):
return StringBuffer(self.force())
- def readbuf_w(self, space):
- return StringBuffer(self.force())
-
def descr_len(self, space):
return space.wrap(self.length)
More information about the pypy-commit
mailing list