Author: Brian Kearns <[email protected]>
Branch: use-file-star-for-file
Changeset: r73557:a35017e41180
Date: 2014-09-16 14:12 -0400
http://bitbucket.org/pypy/pypy/changeset/a35017e41180/
Log: fix readinto sanity checks
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -452,6 +452,8 @@
"""readinto() -> Undocumented. Don't use this; it may go away."""
# XXX not the most efficient solution as it doesn't avoid the copying
space = self.space
+ self.check_closed()
+ self.check_readable()
rwbuffer = space.writebuf_w(w_rwbuffer)
ntodo = rwbuffer.getlength()
ndone = 0
diff --git a/pypy/module/_file/test/test_file_extra.py
b/pypy/module/_file/test/test_file_extra.py
--- a/pypy/module/_file/test/test_file_extra.py
+++ b/pypy/module/_file/test/test_file_extra.py
@@ -582,6 +582,12 @@
assert n == 6
assert len(a) == 10
assert a.tostring() == 'foobar6789'
+ exc = raises(ValueError, f.readinto, bytearray(''))
+ assert str(exc.value) == "I/O operation on closed file"
+ f = open(fn, 'wb')
+ exc = raises(IOError, f.readinto, bytearray(''))
+ assert str(exc.value) == "File not open for reading"
+ f.close()
def test_weakref(self):
"""Files are weakrefable."""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit