[pypy-commit] pypy stdlib-2.7.4: io.BytesIO/StringIO status methods now check_closed before returning (cpython issue15841)

bdkearns noreply at buildbot.pypy.org
Wed Apr 10 06:45:44 CEST 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: stdlib-2.7.4
Changeset: r63193:d01cf553b1f0
Date: 2013-04-10 00:41 -0400
http://bitbucket.org/pypy/pypy/changeset/d01cf553b1f0/

Log:	io.BytesIO/StringIO status methods now check_closed before returning
	(cpython issue15841)

diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -179,12 +179,15 @@
         return space.wrap(self.pos)
 
     def readable_w(self, space):
+        self._check_closed(space)
         return space.w_True
 
     def writable_w(self, space):
+        self._check_closed(space)
         return space.w_True
 
     def seekable_w(self, space):
+        self._check_closed(space)
         return space.w_True
 
     def close_w(self, space):
diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -246,12 +246,15 @@
         return space.wrap(u''.join(self.buf))
 
     def readable_w(self, space):
+        self._check_closed(space)
         return space.w_True
 
     def writable_w(self, space):
+        self._check_closed(space)
         return space.w_True
 
     def seekable_w(self, space):
+        self._check_closed(space)
         return space.w_True
 
     def close_w(self, space):
diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py
--- a/pypy/module/_io/test/test_bytesio.py
+++ b/pypy/module/_io/test/test_bytesio.py
@@ -20,6 +20,9 @@
         assert f.writable()
         assert f.seekable()
         f.close()
+        raises(ValueError, f.readable)
+        raises(ValueError, f.writable)
+        raises(ValueError, f.seekable)
 
     def test_write(self):
         import _io
diff --git a/pypy/module/_io/test/test_stringio.py b/pypy/module/_io/test/test_stringio.py
--- a/pypy/module/_io/test/test_stringio.py
+++ b/pypy/module/_io/test/test_stringio.py
@@ -18,9 +18,9 @@
         assert not sio.closed
         assert not sio.line_buffering
         sio.close()
-        assert sio.readable()
-        assert sio.writable()
-        assert sio.seekable()
+        raises(ValueError, sio.readable)
+        raises(ValueError, sio.writable)
+        raises(ValueError, sio.seekable)
         raises(ValueError, sio.isatty)
         assert sio.closed
         assert sio.errors is None


More information about the pypy-commit mailing list