[Python-checkins] cpython (3.2): Issue #13087: BufferedReader.seek() now always raises UnsupportedOperation
antoine.pitrou
python-checkins at python.org
Tue Oct 4 12:33:00 CEST 2011
http://hg.python.org/cpython/rev/d287f0654349
changeset: 72648:d287f0654349
branch: 3.2
parent: 72642:bf39434dd506
user: Antoine Pitrou <solipsis at pitrou.net>
date: Tue Oct 04 12:26:20 2011 +0200
summary:
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.
files:
Lib/test/test_io.py | 8 ++++++++
Misc/NEWS | 4 ++++
Modules/_io/bufferedio.c | 3 +++
3 files changed, 15 insertions(+), 0 deletions(-)
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
@@ -922,6 +922,14 @@
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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,10 @@
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
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1086,6 +1086,9 @@
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;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list