From 116d83ce710d4494a4d401edb6983aceef45b901 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Sun, 28 Mar 2004 02:20:45 +0000 Subject: [PATCH] SF bug 924242: socket._fileobject._getclosed() returns wrong value The .closed property always returned the wrong result. Bugfix candidate! --- Lib/socket.py | 2 +- Lib/test/test_socket.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/socket.py b/Lib/socket.py index 8e30ce0a34a..39d511962b2 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -217,7 +217,7 @@ class _fileobject(object): self._wbuf = [] # A list of strings def _getclosed(self): - return self._sock is not None + return self._sock is None closed = property(_getclosed, doc="True if the file is closed") def close(self): diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index a2b84894340..f7bf041ebd0 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -590,6 +590,7 @@ class FileObjectClassTestCase(SocketConnectedTest): def tearDown(self): self.serv_file.close() + self.assert_(self.serv_file.closed) self.serv_file = None SocketConnectedTest.tearDown(self) @@ -599,6 +600,7 @@ class FileObjectClassTestCase(SocketConnectedTest): def clientTearDown(self): self.cli_file.close() + self.assert_(self.cli_file.closed) self.cli_file = None SocketConnectedTest.clientTearDown(self) @@ -645,6 +647,12 @@ class FileObjectClassTestCase(SocketConnectedTest): self.cli_file.write(MSG) self.cli_file.flush() + def testClosedAttr(self): + self.assert_(not self.serv_file.closed) + + def _testClosedAttr(self): + self.assert_(not self.cli_file.closed) + class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase): """Repeat the tests from FileObjectClassTestCase with bufsize==0.