Commits

Brian Kearns committed 1e39f97

fix buffer conversion when readonly

  • Participants
  • Parent commits fc458f8
  • Branches refactor-buffer-api

Comments (0)

Files changed (4)

File pypy/module/_io/test/test_bufferedio.py

         raw = _io.FileIO(self.tmpfile)
         f = _io.BufferedReader(raw)
         assert f.readinto(a) == 5
+        exc = raises(TypeError, f.readinto, buffer(b"hello"))
+        assert str(exc.value) == "must be read-write buffer, not buffer"
         exc = raises(TypeError, f.readinto, memoryview(b"hello"))
         assert str(exc.value) == "must be read-write buffer, not memoryview"
         f.close()

File pypy/module/_io/test/test_bytesio.py

         a2 = bytearray('testing')
         assert b.readinto(a1) == 1
         assert b.readinto(a2) == 4
+        exc = raises(TypeError, b.readinto, buffer(b"hello"))
+        assert str(exc.value) == "must be read-write buffer, not buffer"
         exc = raises(TypeError, b.readinto, memoryview(b"hello"))
         assert str(exc.value) == "must be read-write buffer, not memoryview"
         b.close()

File pypy/module/_io/test/test_fileio.py

         a = bytearray('x' * 10)
         f = _io.FileIO(self.tmpfile, 'r+')
         assert f.readinto(a) == 10
+        exc = raises(TypeError, f.readinto, buffer(b"hello"))
+        assert str(exc.value) == "must be read-write buffer, not buffer"
         exc = raises(TypeError, f.readinto, memoryview(b"hello"))
         assert str(exc.value) == "must be read-write buffer, not memoryview"
         f.close()

File pypy/objspace/std/bufferobject.py

         self.buf = buf
 
     def buffer_w(self, space, flags):
+        space.check_buf_flags(flags, self.buf.readonly)
         return self.buf
 
     def readbuf_w(self, space):