Author: Amaury Forgeot d'Arc <[email protected]>
Branch: 
Changeset: r78069:8e323987d093
Date: 2015-06-13 00:57 +0200
http://bitbucket.org/pypy/pypy/changeset/8e323987d093/

Log:    Add old buffer interface to memoryview, this is needed by the struct
        module.

diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -449,6 +449,8 @@
         assert b[:] == ('\x00' * 2 +
                         self.struct.pack("ii", 17, 42) +
                         '\x00' * (19-sz-2))
+        m = memoryview(b)
+        self.struct.pack_into("ii", m, 2, 17, 42)
 
     def test_unpack_from(self):
         b = self.bytebuffer(19)
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
@@ -23,6 +23,14 @@
         space.check_buf_flags(flags, self.buf.readonly)
         return self.buf
 
+    def readbuf_w(self, space):
+        return self.buf
+
+    def writebuf_w(self, space):
+        if self.buf.readonly:
+            raise oefmt(space.w_TypeError, "buffer is read-only")
+        return self.buf
+
     @staticmethod
     def descr_new_memoryview(space, w_subtype, w_object):
         return W_MemoryView(space.buffer_w(w_object, space.BUF_FULL_RO))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to