diff -r 90a06fbb1f85 Lib/test/test_io.py --- a/Lib/test/test_io.py Sat Oct 01 19:22:30 2011 +0200 +++ b/Lib/test/test_io.py Sat Oct 01 18:25:21 2011 -0400 @@ -928,6 +928,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 -r 90a06fbb1f85 Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c Sat Oct 01 19:22:30 2011 +0200 +++ b/Modules/_io/bufferedio.c Sat Oct 01 18:25:21 2011 -0400 @@ -1155,6 +1155,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;