From 1e44fecc52da8fb47ab51a000c48e0ce8f36064c Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 4 Oct 2011 12:26:20 +0200 Subject: 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. --- Lib/test/test_io.py | 8 ++++++++ Misc/NEWS | 4 ++++ Modules/_io/bufferedio.c | 3 +++ 3 files changed, 15 insertions(+) diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 0dc9d6d..53cabbb 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -922,6 +922,14 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): finally: 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): rawio = self.MisbehavedRawIO((b"abc", b"d", b"efg")) bufio = self.tp(rawio) diff --git a/Misc/NEWS b/Misc/NEWS index 2961776..dd98665 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -36,6 +36,10 @@ Core and Builtins 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 metaclass is registered with copyreg. Patch by Nicolas M. ThiƩry and Craig Citro. diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index d6f0c9c..bd1aae5 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1086,6 +1086,9 @@ buffered_seek(buffered *self, PyObject *args) 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); if (target == -1 && PyErr_Occurred()) return NULL; -- cgit v0.12 From 0fc80c0d5a76ed59f3db0b3f15e1e37ccc127ffb Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 4 Oct 2011 12:26:34 +0200 Subject: Add John to ACKS --- Misc/ACKS | 1 + 1 file changed, 1 insertion(+) diff --git a/Misc/ACKS b/Misc/ACKS index 15fb385..4f2ea13 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -652,6 +652,7 @@ Neal Norwitz Michal Nowikowski Steffen Daode Nurpmeso Nigel O'Brian +John O'Connor Kevin O'Connor Tim O'Malley Pascal Oberndoerfer -- cgit v0.12