Kaydet (Commit) 1e44fecc authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Issue #13087: BufferedReader.seek() now always raises UnsupportedOperation

if the underlying raw stream is unseekable, even if the seek could be
satisfied using the internal buffer.  Patch by John O'Connor.
üst 94190bb6
...@@ -922,6 +922,14 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): ...@@ -922,6 +922,14 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
finally: finally:
support.unlink(support.TESTFN) support.unlink(support.TESTFN)
def test_unseekable(self):
bufio = self.tp(self.MockUnseekableIO(b"A" * 10))
self.assertRaises(self.UnsupportedOperation, bufio.tell)
self.assertRaises(self.UnsupportedOperation, bufio.seek, 0)
bufio.read(1)
self.assertRaises(self.UnsupportedOperation, bufio.seek, 0)
self.assertRaises(self.UnsupportedOperation, bufio.tell)
def test_misbehaved_io(self): def test_misbehaved_io(self):
rawio = self.MisbehavedRawIO((b"abc", b"d", b"efg")) rawio = self.MisbehavedRawIO((b"abc", b"d", b"efg"))
bufio = self.tp(rawio) bufio = self.tp(rawio)
......
...@@ -36,6 +36,10 @@ Core and Builtins ...@@ -36,6 +36,10 @@ Core and Builtins
Library Library
------- -------
- Issue #13087: BufferedReader.seek() now always raises UnsupportedOperation
if the underlying raw stream is unseekable, even if the seek could be
satisfied using the internal buffer. Patch by John O'Connor.
- Issue #7689: Allow pickling of dynamically created classes when their - Issue #7689: Allow pickling of dynamically created classes when their
metaclass is registered with copyreg. Patch by Nicolas M. Thiéry and Craig metaclass is registered with copyreg. Patch by Nicolas M. Thiéry and Craig
Citro. Citro.
......
...@@ -1086,6 +1086,9 @@ buffered_seek(buffered *self, PyObject *args) ...@@ -1086,6 +1086,9 @@ buffered_seek(buffered *self, PyObject *args)
CHECK_CLOSED(self, "seek of closed file") CHECK_CLOSED(self, "seek of closed file")
if (_PyIOBase_check_seekable(self->raw, Py_True) == NULL)
return NULL;
target = PyNumber_AsOff_t(targetobj, PyExc_ValueError); target = PyNumber_AsOff_t(targetobj, PyExc_ValueError);
if (target == -1 && PyErr_Occurred()) if (target == -1 && PyErr_Occurred())
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment