diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-25 22:52:37 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-25 22:52:37 +0200 |
commit | 3cbe80839a073044db119fa467316ae2fade6652 (patch) | |
tree | cb62ae4a30a0895e45756ffe961d419c0d1f6cf1 | |
parent | c1a5374ed8894db4bc6fad00e9553ddd046e07a5 (diff) | |
download | cpython-3cbe80839a073044db119fa467316ae2fade6652.tar.gz |
Issue #12175: RawIOBase.readall() now returns None if read() returns None.
-rw-r--r-- | Lib/_pyio.py | 6 | ||||
-rw-r--r-- | Lib/test/test_io.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/_io/iobase.c | 8 |
4 files changed, 20 insertions, 3 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index dc68d049a8..76a2d5f78b 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -560,7 +560,11 @@ class RawIOBase(IOBase): if not data: break res += data - return bytes(res) + if res: + return bytes(res) + else: + # b'' or None + return data def readinto(self, b): """Read up to len(b) bytes into b. diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 9b18b70488..d0608e3b85 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -798,14 +798,17 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): # Inject some None's in there to simulate EWOULDBLOCK rawio = self.MockRawIO((b"abc", b"d", None, b"efg", None, None, None)) bufio = self.tp(rawio) - self.assertEqual(b"abcd", bufio.read(6)) self.assertEqual(b"e", bufio.read(1)) self.assertEqual(b"fg", bufio.read()) self.assertEqual(b"", bufio.peek(1)) - self.assertTrue(None is bufio.read()) + self.assertIsNone(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): rawio = self.MockRawIO((b"abc", b"d", b"efg")) bufio = self.tp(rawio) @@ -83,6 +83,8 @@ Core and Builtins Library ------- +- Issue #12175: RawIOBase.readall() now returns None if read() returns None. + - Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError if the file is closed. diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index e129ca9068..176761d537 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -814,6 +814,14 @@ rawiobase_readall(PyObject *self, PyObject *args) Py_DECREF(chunks); 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)) { Py_DECREF(chunks); Py_DECREF(data); |