From: Victor Stinner Date: Tue, 4 Jan 2011 11:00:45 +0000 (+0000) Subject: Issue #10819: SocketIO.name property returns -1 when its closed, instead of X-Git-Tag: v3.2rc1~202 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3a51ecb8518540625034ff07f9d518e0f84e7ac;p=python Issue #10819: SocketIO.name property returns -1 when its closed, instead of raising a ValueError, to fix repr(). --- diff --git a/Lib/socket.py b/Lib/socket.py index 2dc97369d3..d0da7409bb 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -307,7 +307,10 @@ class SocketIO(io.RawIOBase): @property def name(self): - return self.fileno() + if not self.closed: + return self.fileno() + else: + return -1 @property def mode(self): diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 4c8c7d666a..8f96fe48a3 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -738,6 +738,12 @@ class GeneralModuleTests(unittest.TestCase): f = None 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.') class BasicTCPTest(SocketConnectedTest): diff --git a/Misc/NEWS b/Misc/NEWS index 1b77950249..bebe16b9b5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -30,6 +30,9 @@ Core and Builtins 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 the input buffer length doesn't fit into an unsigned int (length bigger than 2^32-1 bytes).