Commits

Brian Kearns committed 0fa3dc3

revert this _io change, not worth differing from cpython

Comments (0)

Files changed (2)

pypy/module/_io/interp_bufferedio.py

             raise operationerrfmt(space.w_ValueError,
                 "whence must be between 0 and 2, not %d", whence)
         self._check_closed(space, "seek of closed file")
-        if whence != 2 and self.readable and self.read_end != -1:
+        if whence != 2 and self.readable:
             # Check if seeking leaves us inside the current buffer, so as to
             # return quickly if possible. Also, we needn't take the lock in
             # this fast path.
                 self._raw_tell(space)
             current = self.abs_pos
             available = self._readahead()
-            if whence == 0:
-                offset = pos - (current - self._raw_offset())
-            else:
-                offset = pos
-            if -self.pos <= offset <= available:
-                newpos = self.pos + offset
-                assert newpos >= 0
-                self.pos = newpos
-                return space.wrap(current - available + offset)
+            if available > 0:
+                if whence == 0:
+                    offset = pos - (current - self._raw_offset())
+                else:
+                    offset = pos
+                if -self.pos <= offset <= available:
+                    newpos = self.pos + offset
+                    assert newpos >= 0
+                    self.pos = newpos
+                    return space.wrap(current - available + offset)
 
         # Fallback: invoke raw seek() method and clear buffer
         with self.lock:

pypy/module/_io/test/test_bufferedio.py

         assert f.read() == "\nc"
         f.close()
 
-    def test_seek_nocall(self):
-        # test that when we're at the end of the buffer,
-        # an in-buffer back seek doesn't produce a raw seek
-        import _io
-        raw = _io.FileIO(self.tmpfile)
-        f = _io.BufferedReader(raw, buffer_size=3)
-        f.read(1)
-        f.seek(3, 0)
-        def failing_seek(*args):
-            assert False
-        raw.seek = failing_seek
-        f.seek(-1, 1)
-
     def test_readlines(self):
         import _io
         raw = _io.FileIO(self.tmpfile)
                 expected[j] = 2
                 expected[i] = 1
                 assert raw.getvalue() == str(expected)
-        
+
     def test_interleaved_read_write(self):
         import _io as io
         # Test for issue #12213
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.