[Python-checkins] cpython (merge 3.1 -> 3.2): (Merge 3.1) Issue #12175: RawIOBase.readall() now returns None if read()
victor.stinner
python-checkins at python.org
Wed May 25 22:53:58 CEST 2011
http://hg.python.org/cpython/rev/fb29dc650d24
changeset: 70386:fb29dc650d24
branch: 3.2
parent: 70382:745e373c0b8e
parent: 70385:4a7118cff1d3
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Wed May 25 22:49:15 2011 +0200
summary:
(Merge 3.1) Issue #12175: RawIOBase.readall() now returns None if read()
returns None.
files:
Lib/_pyio.py | 6 +++++-
Lib/test/test_io.py | 7 +++++--
Misc/NEWS | 8 +++++---
Modules/_io/iobase.c | 8 ++++++++
4 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -558,7 +558,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 bytearray b.
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -827,14 +827,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 --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,11 @@
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.
+
- Issue #12070: Fix the Makefile parser of the sysconfig module to handle
correctly references to "bogus variable" (e.g. "prefix=$/opt/python").
@@ -731,9 +736,6 @@
Library
-------
-- Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError
- if the file is closed.
-
- Issue #10916: mmap should not segfault when a file is mapped using 0 as length
and a non-zero offset, and an attempt to read past the end of file is made
(IndexError is raised instead). Patch by Ross Lagerwall.
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -815,6 +815,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);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list