Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r66099:b134074e011c
Date: 2013-08-12 18:41 -0400
http://bitbucket.org/pypy/pypy/changeset/b134074e011c/
Log: Fixed #1582 -- Corrected the behavior of file.seek(X, os.SEEK_CUR)
when it raises an IOError
diff --git a/pypy/module/_file/test/test_file.py
b/pypy/module/_file/test/test_file.py
--- a/pypy/module/_file/test/test_file.py
+++ b/pypy/module/_file/test/test_file.py
@@ -385,6 +385,24 @@
raise Exception("time out")
print 'Passed.'
+ def test_seek_from_cur_backwards_off_end(self):
+ import os
+
+ f = self.file(self.temppath, "w+b")
+ f.write('123456789x12345678><123456789\n')
+
+ f.seek(0, os.SEEK_END)
+ f.seek(-25, os.SEEK_CUR)
+ f.read(25)
+ f.seek(-25, os.SEEK_CUR)
+ try:
+ f.seek(-25, os.SEEK_CUR)
+ except IOError:
+ pass
+ else:
+ raise AssertionError("Didn't raise IOError")
+ assert f.tell() == 5
+
class AppTestFile25:
spaceconfig = dict(usemodules=("_file",))
diff --git a/rpython/rlib/streamio.py b/rpython/rlib/streamio.py
--- a/rpython/rlib/streamio.py
+++ b/rpython/rlib/streamio.py
@@ -558,19 +558,22 @@
if -self.pos <= difpos <= currentsize:
self.pos += difpos
return
- self.buf = ""
- self.pos = 0
if whence == 1:
offset -= currentsize
try:
self.do_seek(offset, whence)
except MyNotImplementedError:
+ self.buf = ""
+ self.pos = 0
if difpos < 0:
raise
if whence == 0:
offset = difpos - currentsize
intoffset = offset2int(offset)
self.read(intoffset)
+ else:
+ self.buf = ""
+ self.pos = 0
return
if whence == 2:
try:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit