Issue #12175: RawIOBase.readall() now returns None if read() returns None.
This commit is contained in:
parent
5100a405dc
commit
daf17e9bc8
|
@ -560,7 +560,11 @@ class RawIOBase(IOBase):
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
res += data
|
res += data
|
||||||
return bytes(res)
|
if res:
|
||||||
|
return bytes(res)
|
||||||
|
else:
|
||||||
|
# b'' or None
|
||||||
|
return data
|
||||||
|
|
||||||
def readinto(self, b):
|
def readinto(self, b):
|
||||||
"""Read up to len(b) bytes into b.
|
"""Read up to len(b) bytes into b.
|
||||||
|
|
|
@ -798,14 +798,17 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
|
||||||
# Inject some None's in there to simulate EWOULDBLOCK
|
# Inject some None's in there to simulate EWOULDBLOCK
|
||||||
rawio = self.MockRawIO((b"abc", b"d", None, b"efg", None, None, None))
|
rawio = self.MockRawIO((b"abc", b"d", None, b"efg", None, None, None))
|
||||||
bufio = self.tp(rawio)
|
bufio = self.tp(rawio)
|
||||||
|
|
||||||
self.assertEqual(b"abcd", bufio.read(6))
|
self.assertEqual(b"abcd", bufio.read(6))
|
||||||
self.assertEqual(b"e", bufio.read(1))
|
self.assertEqual(b"e", bufio.read(1))
|
||||||
self.assertEqual(b"fg", bufio.read())
|
self.assertEqual(b"fg", bufio.read())
|
||||||
self.assertEqual(b"", bufio.peek(1))
|
self.assertEqual(b"", bufio.peek(1))
|
||||||
self.assertTrue(None is bufio.read())
|
self.assertIsNone(bufio.read())
|
||||||
self.assertEqual(b"", bufio.read())
|
self.assertEqual(b"", bufio.read())
|
||||||
|
|
||||||
|
rawio = self.MockRawIO((b"a", None, None))
|
||||||
|
self.assertEqual(b"a", rawio.readall())
|
||||||
|
self.assertIsNone(rawio.readall())
|
||||||
|
|
||||||
def test_read_past_eof(self):
|
def test_read_past_eof(self):
|
||||||
rawio = self.MockRawIO((b"abc", b"d", b"efg"))
|
rawio = self.MockRawIO((b"abc", b"d", b"efg"))
|
||||||
bufio = self.tp(rawio)
|
bufio = self.tp(rawio)
|
||||||
|
|
|
@ -83,6 +83,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #12175: RawIOBase.readall() now returns None if read() returns None.
|
||||||
|
|
||||||
- Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError
|
- Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError
|
||||||
if the file is closed.
|
if the file is closed.
|
||||||
|
|
||||||
|
|
|
@ -814,6 +814,14 @@ rawiobase_readall(PyObject *self, PyObject *args)
|
||||||
Py_DECREF(chunks);
|
Py_DECREF(chunks);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (data == Py_None) {
|
||||||
|
if (PyList_GET_SIZE(chunks) == 0) {
|
||||||
|
Py_DECREF(chunks);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
Py_DECREF(data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!PyBytes_Check(data)) {
|
if (!PyBytes_Check(data)) {
|
||||||
Py_DECREF(chunks);
|
Py_DECREF(chunks);
|
||||||
Py_DECREF(data);
|
Py_DECREF(data);
|
||||||
|
|
Loading…
Reference in New Issue