cpython: c27e9dcad1a3 (original) (raw)

Mercurial > cpython

changeset 100808:c27e9dcad1a3

Issue #22854: Merge UnsupportedOperation fixes from 3.5 [#22854]

Martin Panter vadmium+py@gmail.com
date Thu, 31 Mar 2016 08:25:59 +0000
parents b6eebe7cf5ae(current diff)dc9e5f09ac0c(diff)
children fb10d1f5016e
files Lib/_pyio.py Lib/test/test_io.py Misc/NEWS Modules/_io/bufferedio.c Modules/_io/iobase.c
diffstat 6 files changed, 130 insertions(+), 35 deletions(-)[+] [-] Lib/_pyio.py 18 Lib/test/test_io.py 116 Misc/NEWS 3 Modules/_io/bufferedio.c 2 Modules/_io/clinic/iobase.c.h 10 Modules/_io/iobase.c 16

line wrap: on

line diff

--- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -390,7 +390,7 @@ class IOBase(metaclass=abc.ABCMeta): def seekable(self): """Return a bool indicating whether object supports random access.

@@ -405,7 +405,7 @@ class IOBase(metaclass=abc.ABCMeta): def readable(self): """Return a bool indicating whether object was opened for reading.

@@ -419,7 +419,7 @@ class IOBase(metaclass=abc.ABCMeta): def writable(self): """Return a bool indicating whether object was opened for writing.

@@ -787,12 +787,6 @@ class _BufferedIOMixin(BufferedIOBase): def seekable(self): return self.raw.seekable()

-

- @property def raw(self): return self._raw @@ -982,6 +976,9 @@ class BufferedReader(_BufferedIOMixin): self._reset_read_buf() self._read_lock = Lock()

+ def _reset_read_buf(self): self._read_buf = b"" self._read_pos = 0 @@ -1170,6 +1167,9 @@ class BufferedWriter(_BufferedIOMixin): self._write_buf = bytearray() self._write_lock = Lock()

+ def write(self, b): if self.closed: raise ValueError("write to closed file")

--- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -203,6 +203,9 @@ class MockUnseekableIO: def tell(self, *args): raise self.UnsupportedOperation("not seekable")

+ class CMockUnseekableIO(MockUnseekableIO, io.BytesIO): UnsupportedOperation = io.UnsupportedOperation @@ -361,6 +364,107 @@ class IOTest(unittest.TestCase): self.assertRaises(exc, fp.seek, 1, self.SEEK_CUR) self.assertRaises(exc, fp.seek, -1, self.SEEK_END)

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+ def test_open_handles_NUL_chars(self): fn_with_NUL = 'foo\0bar' self.assertRaises(ValueError, self.open, fn_with_NUL, 'w') @@ -751,12 +855,6 @@ class CommonBufferedTests: self.assertEqual(42, bufio.fileno())

- def test_invalid_args(self): rawio = self.MockRawIO() bufio = self.tp(rawio) @@ -784,13 +882,9 @@ class CommonBufferedTests: super().flush() rawio = self.MockRawIO() bufio = MyBufferedIO(rawio)

def test_context_manager(self): # Test usability as a context manager

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,9 @@ Core and Builtins Library ------- +- Issue #22854: Change BufferedReader.writable() and

--- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -2398,7 +2398,6 @@ static PyMethodDef bufferedreader_method {"close", (PyCFunction)buffered_close, METH_NOARGS}, {"seekable", (PyCFunction)buffered_seekable, METH_NOARGS}, {"readable", (PyCFunction)buffered_readable, METH_NOARGS},

--- a/Modules/_io/clinic/iobase.c.h +++ b/Modules/io/clinic/iobase.c.h @@ -66,7 +66,7 @@ PyDoc_STRVAR(io__IOBase_seekable__doc "\n" "Return whether object supports random access.\n" "\n" -"If False, seek(), tell() and truncate() will raise UnsupportedOperation.\n" +"If False, seek(), tell() and truncate() will raise OSError.\n" "This method may need to do a test seek()."); #define IO__IOBASE_SEEKABLE_METHODDEF [](#l5.11) @@ -87,7 +87,7 @@ PyDoc_STRVAR(io__IOBase_readable__doc "\n" "Return whether object was opened for reading.\n" "\n" -"If False, read() will raise UnsupportedOperation."); +"If False, read() will raise OSError."); #define IO__IOBASE_READABLE_METHODDEF [](#l5.19) {"readable", (PyCFunction)io__IOBase_readable, METH_NOARGS, io__IOBase_readable__doc}, @@ -107,7 +107,7 @@ PyDoc_STRVAR(io__IOBase_writable__doc "\n" "Return whether object was opened for writing.\n" "\n" -"If False, write() will raise UnsupportedOperation."); +"If False, write() will raise OSError."); #define IO__IOBASE_WRITABLE_METHODDEF [](#l5.28) {"writable", (PyCFunction)io__IOBase_writable, METH_NOARGS, io__IOBase_writable__doc}, @@ -127,7 +127,7 @@ PyDoc_STRVAR(io__IOBase_fileno__doc, "\n" "Returns underlying file descriptor if one exists.\n" "\n" -"An IOError is raised if the IO object does not use a file descriptor."); +"OSError is raised if the IO object does not use a file descriptor."); #define _IO__IOBASE_FILENO_METHODDEF [](#l5.37) {"fileno", (PyCFunction)io__IOBase_fileno, METH_NOARGS, io__IOBase_fileno__doc}, @@ -276,4 +276,4 @@ static PyObject { return _io__RawIOBase_readall_impl(self); } -/[clinic end generated code: output=fe034152b6884e65 input=a9049054013a1b77]/ +/[clinic end generated code: output=b874952f5cc248a4 input=a9049054013a1b77]*/

--- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -335,13 +335,13 @@ iobase_dealloc(iobase self) Return whether object supports random access. -If False, seek(), tell() and truncate() will raise UnsupportedOperation. +If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek(). [clinic start generated code]/ static PyObject _io__IOBase_seekable_impl(PyObject self) -/[clinic end generated code: output=4c24c67f5f32a43d input=22676eebb81dcf1e]/ +/[clinic end generated code: output=4c24c67f5f32a43d input=b976622f7fdf3063]/ { Py_RETURN_FALSE; } @@ -368,12 +368,12 @@ PyObject Return whether object was opened for reading. -If False, read() will raise UnsupportedOperation. +If False, read() will raise OSError. [clinic start generated code]/ static PyObject _io__IOBase_readable_impl(PyObject self) -/[clinic end generated code: output=e48089250686388b input=12fc3d8f6be46434]/ +/[clinic end generated code: output=e48089250686388b input=285b3b866a0ec35f]/ { Py_RETURN_FALSE; } @@ -401,12 +401,12 @@ PyObject Return whether object was opened for writing. -If False, write() will raise UnsupportedOperation. +If False, write() will raise OSError. [clinic start generated code]/ static PyObject _io__IOBase_writable_impl(PyObject self) -/[clinic end generated code: output=406001d0985be14f input=c17a0bb6a8dfc590]/ +/[clinic end generated code: output=406001d0985be14f input=9dcac18a013a05b5]/ { Py_RETURN_FALSE; } @@ -456,12 +456,12 @@ iobase_exit(PyObject self, PyObject ar Returns underlying file descriptor if one exists. -An IOError is raised if the IO object does not use a file descriptor. +OSError is raised if the IO object does not use a file descriptor. [clinic start generated code]/ static PyObject _io__IOBase_fileno_impl(PyObject self) -/[clinic end generated code: output=7cc0973f0f5f3b73 input=32773c5df4b7eede]/ +/[clinic end generated code: output=7cc0973f0f5f3b73 input=4e37028947dc1cc8]*/ { return iobase_unsupported("fileno"); }