mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
(Merge 3.2) Issue #12175: RawIOBase.readall() now returns None if read()
returns None.
This commit is contained in:
commit
d2780aedce
4 changed files with 28 additions and 11 deletions
|
@ -558,7 +558,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 bytearray b.
|
||||
|
|
|
@ -833,14 +833,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)
|
||||
|
|
18
Misc/NEWS
18
Misc/NEWS
|
@ -161,11 +161,16 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #11109 - New service_action method for BaseServer, used by
|
||||
ForkingMixin class for cleanup. Initial Patch by Justin Wark.
|
||||
|
||||
- Issue #12045: Avoid duplicate execution of command in ctypes.util._get_soname().
|
||||
Patch by Sijin Joseph.
|
||||
- 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 #11109: New service_action method for BaseServer, used by ForkingMixin
|
||||
class for cleanup. Initial Patch by Justin Wark.
|
||||
|
||||
- Issue #12045: Avoid duplicate execution of command in
|
||||
ctypes.util._get_soname(). Patch by Sijin Joseph.
|
||||
|
||||
- Issue #10818: Remove the Tk GUI and the serve() function of the pydoc module,
|
||||
pydoc -g has been deprecated in Python 3.2 and it has a new enhanced web
|
||||
|
@ -1062,9 +1067,6 @@ Core and Builtins
|
|||
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.
|
||||
|
|
|
@ -815,6 +815,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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue