From 9d24ff027fe93e702d95d95dd520096d4c5a9fc2 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Thu, 20 Nov 2008 23:15:52 +0000 Subject: [PATCH] Follow-up of r67300: correct a failure in socket.makefile(). SocketIO objects now always have 'name' and 'mode' attributes. --- Lib/socket.py | 13 ++++++++----- Lib/test/test_socket.py | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Lib/socket.py b/Lib/socket.py index fcbc545d5ac..5578b13b1a3 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -149,8 +149,6 @@ class socket(_socket.socket): if buffering == 0: if not binary: raise ValueError("unbuffered streams must be binary") - raw.name = self.fileno() - raw.mode = mode return raw if reading and writing: buffer = io.BufferedRWPair(raw, raw, buffering) @@ -160,11 +158,8 @@ class socket(_socket.socket): assert writing buffer = io.BufferedWriter(raw, buffering) if binary: - buffer.name = self.fileno() - buffer.mode = mode return buffer text = io.TextIOWrapper(buffer, encoding, newline) - text.name = self.fileno() text.mode = mode return text @@ -230,6 +225,14 @@ class SocketIO(io.RawIOBase): def fileno(self): return self._sock.fileno() + @property + def name(self): + return self._sock.fileno() + + @property + def mode(self): + return self._mode + def close(self): if self.closed: return diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 9d753b7ea53..b2323fe7fd2 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -848,6 +848,14 @@ class FileObjectClassTestCase(SocketConnectedTest): def _testClosedAttr(self): self.assert_(not self.cli_file.closed) + def testAttributes(self): + self.assertEqual(self.serv_file.mode, 'r') + self.assertEqual(self.serv_file.name, self.cli_conn.fileno()) + + def _testAttributes(self): + self.assertEqual(self.cli_file.mode, 'w') + self.assertEqual(self.cli_file.name, self.serv_conn.fileno()) + class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase): """Repeat the tests from FileObjectClassTestCase with bufsize==0.