1. Armin Rigo
  2. cpython-withatomic

Commits

Amaury Forgeot d'Arc  committed 5ffd67d

Follow-up of r67300: correct a failure in socket.makefile().
SocketIO objects now always have 'name' and 'mode' attributes.

  • Participants
  • Parent commits dc1db46
  • Branches default

Comments (0)

Files changed (2)

File Lib/socket.py

View file
  • Ignore whitespace
         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)
             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
 
     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

File Lib/test/test_socket.py

View file
  • Ignore whitespace
     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.