changeset: 70388:43a498da8680 branch: 2.7 parent: 70384:f2414bb35c96 user: Victor Stinner date: Wed May 25 22:52:37 2011 +0200 files: Lib/_pyio.py Lib/test/test_io.py Misc/NEWS Modules/_io/iobase.c description: Issue #12175: RawIOBase.readall() now returns None if read() returns None. diff -r f2414bb35c96 -r 43a498da8680 Lib/_pyio.py --- a/Lib/_pyio.py Wed May 25 22:15:36 2011 +0200 +++ b/Lib/_pyio.py Wed May 25 22:52:37 2011 +0200 @@ -560,7 +560,11 @@ 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 -r f2414bb35c96 -r 43a498da8680 Lib/test/test_io.py --- a/Lib/test/test_io.py Wed May 25 22:15:36 2011 +0200 +++ b/Lib/test/test_io.py Wed May 25 22:52:37 2011 +0200 @@ -798,14 +798,17 @@ # 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) diff -r f2414bb35c96 -r 43a498da8680 Misc/NEWS --- a/Misc/NEWS Wed May 25 22:15:36 2011 +0200 +++ b/Misc/NEWS Wed May 25 22:52:37 2011 +0200 @@ -83,6 +83,8 @@ 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 -r f2414bb35c96 -r 43a498da8680 Modules/_io/iobase.c --- a/Modules/_io/iobase.c Wed May 25 22:15:36 2011 +0200 +++ b/Modules/_io/iobase.c Wed May 25 22:52:37 2011 +0200 @@ -814,6 +814,14 @@ 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);