Discussion:
[Python-3000-checkins] r67306 - in python/branches/py3k/Lib: socket.py test/test_socket.py
amaury.forgeotdarc
2008-11-20 23:15:53 UTC
Permalink
Author: amaury.forgeotdarc
Date: Fri Nov 21 00:15:52 2008
New Revision: 67306

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


Modified:
python/branches/py3k/Lib/socket.py
python/branches/py3k/Lib/test/test_socket.py

Modified: python/branches/py3k/Lib/socket.py
==============================================================================
--- python/branches/py3k/Lib/socket.py (original)
+++ python/branches/py3k/Lib/socket.py Fri Nov 21 00:15:52 2008
@@ -149,8 +149,6 @@
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 @@
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 @@
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

Modified: python/branches/py3k/Lib/test/test_socket.py
==============================================================================
--- python/branches/py3k/Lib/test/test_socket.py (original)
+++ python/branches/py3k/Lib/test/test_socket.py Fri Nov 21 00:15:52 2008
@@ -848,6 +848,14 @@
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.
Loading...