Commit c3a51ecb authored by Victor Stinner's avatar Victor Stinner

Issue #10819: SocketIO.name property returns -1 when its closed, instead of

raising a ValueError, to fix repr().
parent 8848c7a3
...@@ -307,7 +307,10 @@ class SocketIO(io.RawIOBase): ...@@ -307,7 +307,10 @@ class SocketIO(io.RawIOBase):
@property @property
def name(self): def name(self):
return self.fileno() if not self.closed:
return self.fileno()
else:
return -1
@property @property
def mode(self): def mode(self):
......
...@@ -738,6 +738,12 @@ class GeneralModuleTests(unittest.TestCase): ...@@ -738,6 +738,12 @@ class GeneralModuleTests(unittest.TestCase):
f = None f = None
support.gc_collect() support.gc_collect()
def test_name_closed_socketio(self):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
fp = sock.makefile("rb")
fp.close()
self.assertEqual(repr(fp), "<_io.BufferedReader name=-1>")
@unittest.skipUnless(thread, 'Threading required for this test.') @unittest.skipUnless(thread, 'Threading required for this test.')
class BasicTCPTest(SocketConnectedTest): class BasicTCPTest(SocketConnectedTest):
......
...@@ -30,6 +30,9 @@ Core and Builtins ...@@ -30,6 +30,9 @@ Core and Builtins
Library Library
------- -------
- Issue #10819: SocketIO.name property returns -1 when its closed, instead of
raising a ValueError, to fix repr().
- Issue #8650: zlib.compress() and zlib.decompress() raise an OverflowError if - Issue #8650: zlib.compress() and zlib.decompress() raise an OverflowError if
the input buffer length doesn't fit into an unsigned int (length bigger than the input buffer length doesn't fit into an unsigned int (length bigger than
2^32-1 bytes). 2^32-1 bytes).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment