Repository navigation
gh-158952: Reject read-only buffers before reading in _pyio #158953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
eedc052
3831e0c
a7d0e02
f46989f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -568,6 +568,20 @@ def test_readinto(self): | |
| memio.readinto(b) | ||
| self.assertEqual(b, b"") | ||
|
|
||
| @support.subTests("method", ("readinto", "readinto1")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we need the same test with memory IO (StringIO and BytesIO) and BufferedIO would be better to write it once as a test helper or put somewhere both can use rather than the duplicated implementation (there's a |
||
| @support.subTests("buffer", ( | ||
| b"xxx", memoryview(b"xxx"), b"", memoryview(b""), | ||
| )) | ||
| @support.subTests("position", (0, 4, 10)) | ||
| def test_readinto_readonly_buffer(self, method, buffer, position): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would fit better in test_bufferedio. Goal for me is to test all the Buffered I/O implementations readinto a readonly buffer doesn't advance. That the others implement it right already is nice, but a good thing to make sure we keep. test_general IOTest would also work well as a spot but I don't like it quite as much just because it keeps adding to the big ball of general tests.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Added a shared test in The shared test uses nonempty targets with data remaining: the Python buffered readers currently return 0 for empty targets or at EOF, whereas the C implementations reject them. The existing The full |
||
| data = b"abcdef" | ||
| with self.ioclass(data) as memio: | ||
| memio.seek(position) | ||
| op = getattr(memio, method) | ||
| self.assertRaises(TypeError, op, buffer) | ||
| self.assertEqual(memio.tell(), position) | ||
| self.assertEqual(memio.read(), data[position:]) | ||
|
|
||
| def test_relative_seek(self): | ||
| buf = self.buftype("1234567890") | ||
| memio = self.ioclass(buf) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The pure Python implementation of :meth:`io.BufferedIOBase.readinto` and | ||
| :meth:`~io.BufferedIOBase.readinto1` now rejects read-only buffers before | ||
| reading input, without changing the stream position. |
Uh oh!
There was an error while loading. Please reload this page.