Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Patch by Alessandro Moura.
This commit is contained in:
commit
9b1c84b586
|
@ -324,12 +324,23 @@ class SocketIO(io.RawIOBase):
|
||||||
def readable(self):
|
def readable(self):
|
||||||
"""True if the SocketIO is open for reading.
|
"""True if the SocketIO is open for reading.
|
||||||
"""
|
"""
|
||||||
return self._reading and not self.closed
|
if self.closed:
|
||||||
|
raise ValueError("I/O operation on closed socket.")
|
||||||
|
return self._reading
|
||||||
|
|
||||||
def writable(self):
|
def writable(self):
|
||||||
"""True if the SocketIO is open for writing.
|
"""True if the SocketIO is open for writing.
|
||||||
"""
|
"""
|
||||||
return self._writing and not self.closed
|
if self.closed:
|
||||||
|
raise ValueError("I/O operation on closed socket.")
|
||||||
|
return self._writing
|
||||||
|
|
||||||
|
def seekable(self):
|
||||||
|
"""True if the SocketIO is open for seeking.
|
||||||
|
"""
|
||||||
|
if self.closed:
|
||||||
|
raise ValueError("I/O operation on closed socket.")
|
||||||
|
return super().seekable()
|
||||||
|
|
||||||
def fileno(self):
|
def fileno(self):
|
||||||
"""Return the file descriptor of the underlying socket.
|
"""Return the file descriptor of the underlying socket.
|
||||||
|
|
|
@ -1245,6 +1245,17 @@ class GeneralModuleTests(unittest.TestCase):
|
||||||
fp.close()
|
fp.close()
|
||||||
self.assertEqual(repr(fp), "<_io.BufferedReader name=-1>")
|
self.assertEqual(repr(fp), "<_io.BufferedReader name=-1>")
|
||||||
|
|
||||||
|
def test_unusable_closed_socketio(self):
|
||||||
|
with socket.socket() as sock:
|
||||||
|
fp = sock.makefile("rb", buffering=0)
|
||||||
|
self.assertTrue(fp.readable())
|
||||||
|
self.assertFalse(fp.writable())
|
||||||
|
self.assertFalse(fp.seekable())
|
||||||
|
fp.close()
|
||||||
|
self.assertRaises(ValueError, fp.readable)
|
||||||
|
self.assertRaises(ValueError, fp.writable)
|
||||||
|
self.assertRaises(ValueError, fp.seekable)
|
||||||
|
|
||||||
def test_pickle(self):
|
def test_pickle(self):
|
||||||
sock = socket.socket()
|
sock = socket.socket()
|
||||||
with sock:
|
with sock:
|
||||||
|
|
|
@ -29,6 +29,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #15842: the SocketIO.{readable,writable,seekable} methods now
|
||||||
|
raise ValueError when the file-like object is closed. Patch by Alessandro
|
||||||
|
Moura.
|
||||||
|
|
||||||
- Issue #15882: Change _decimal to accept any coefficient tuple when
|
- Issue #15882: Change _decimal to accept any coefficient tuple when
|
||||||
constructing infinities. This is done for backwards compatibility
|
constructing infinities. This is done for backwards compatibility
|
||||||
with decimal.py: Infinity coefficients are undefined in _decimal
|
with decimal.py: Infinity coefficients are undefined in _decimal
|
||||||
|
|
Loading…
Reference in New Issue