File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -928,6 +928,14 @@ def f():
928928 finally :
929929 support .unlink (support .TESTFN )
930930
931+ def test_unseekable (self ):
932+ bufio = self .tp (self .MockUnseekableIO (b"A" * 10 ))
933+ self .assertRaises (self .UnsupportedOperation , bufio .tell )
934+ self .assertRaises (self .UnsupportedOperation , bufio .seek , 0 )
935+ bufio .read (1 )
936+ self .assertRaises (self .UnsupportedOperation , bufio .seek , 0 )
937+ self .assertRaises (self .UnsupportedOperation , bufio .tell )
938+
931939 def test_misbehaved_io (self ):
932940 rawio = self .MisbehavedRawIO ((b"abc" , b"d" , b"efg" ))
933941 bufio = self .tp (rawio )
Original file line number Diff line number Diff line change @@ -294,6 +294,10 @@ Core and Builtins
294294Library
295295-------
296296
297+ - Issue #13087: BufferedReader.seek() now always raises UnsupportedOperation
298+ if the underlying raw stream is unseekable, even if the seek could be
299+ satisfied using the internal buffer. Patch by John O'Connor.
300+
297301- Issue #7689: Allow pickling of dynamically created classes when their
298302 metaclass is registered with copyreg. Patch by Nicolas M. Thiéry and Craig
299303 Citro.
Original file line number Diff line number Diff line change @@ -1155,6 +1155,9 @@ buffered_seek(buffered *self, PyObject *args)
11551155
11561156 CHECK_CLOSED (self , "seek of closed file" )
11571157
1158+ if (_PyIOBase_check_seekable (self -> raw , Py_True ) == NULL )
1159+ return NULL ;
1160+
11581161 target = PyNumber_AsOff_t (targetobj , PyExc_ValueError );
11591162 if (target == -1 && PyErr_Occurred ())
11601163 return NULL ;
You can’t perform that action at this time.
0 commit comments