[Python-checkins] r43196 - in python/trunk: Doc/lib/libsocket.tex Lib/socket.py Lib/test/test_socket.py

georg.brandl python-checkins at python.org
Tue Mar 21 19:17:26 CET 2006


Author: georg.brandl
Date: Tue Mar 21 19:17:25 2006
New Revision: 43196

Modified:
   python/trunk/Doc/lib/libsocket.tex
   python/trunk/Lib/socket.py
   python/trunk/Lib/test/test_socket.py
Log:
Correct API design mistake from rev. 43126: make socket attributes readonly properties.



Modified: python/trunk/Doc/lib/libsocket.tex
==============================================================================
--- python/trunk/Doc/lib/libsocket.tex	(original)
+++ python/trunk/Doc/lib/libsocket.tex	Tue Mar 21 19:17:25 2006
@@ -654,21 +654,6 @@
 setting, and in general it is recommended to call
 \method{settimeout()} before calling \method{connect()}.
 
-\begin{methoddesc}[socket]{getfamily}{}
-Return the socket family, as given to the \class{socket} constructor.
-\versionadded{2.5}
-\end{methoddesc}
-
-\begin{methoddesc}[socket]{gettype}{}
-Return the socket type, as given to the \class{socket} constructor.
-\versionadded{2.5}
-\end{methoddesc}
-
-\begin{methoddesc}[socket]{getproto}{}
-Return the socket protocol, as given to the \class{socket} constructor.
-\versionadded{2.5}
-\end{methoddesc}
-
 \begin{methoddesc}[socket]{setsockopt}{level, optname, value}
 Set the value of the given socket option (see the \UNIX{} manual page
 \manpage{setsockopt}{2}).  The needed symbolic constants are defined in
@@ -692,6 +677,25 @@
 instead.
 
 
+Socket objects also have these (read-only) attributes that correspond
+to the values given to the \class{socket} constructor.
+
+\begin{memberdesc}[socket]{family}
+The socket family.
+\versionadded{2.5}
+\end{memberdesc}
+
+\begin{memberdesc}[socket]{type}
+The socket type.
+\versionadded{2.5}
+\end{memberdesc}
+
+\begin{memberdesc}[socket]{proto}
+The socket protocol.
+\versionadded{2.5}
+\end{memberdesc}
+
+
 \subsection{SSL Objects \label{ssl-objects}}
 
 SSL objects have the following methods.

Modified: python/trunk/Lib/socket.py
==============================================================================
--- python/trunk/Lib/socket.py	(original)
+++ python/trunk/Lib/socket.py	Tue Mar 21 19:17:25 2006
@@ -182,24 +182,10 @@
         Return a regular file object corresponding to the socket.  The mode
         and bufsize arguments are as for the built-in open() function."""
         return _fileobject(self._sock, mode, bufsize)
-
-    def getfamily(self):
-        """getfamily() -> socket family
-
-        Return the socket family."""
-        return self._sock.family
-
-    def gettype(self):
-        """gettype() -> socket type
-
-        Return the socket type."""
-        return self._sock.type
-
-    def getproto(self):
-        """getproto() -> socket protocol
-
-        Return the socket protocol."""
-        return self._sock.proto
+    
+    family = property(lambda self: self._sock.family, doc="the socket family")
+    type = property(lambda self: self._sock.type, doc="the socket type")
+    proto = property(lambda self: self._sock.proto, doc="the socket protocol")
 
     _s = ("def %s(self, *args): return self._sock.%s(*args)\n\n"
           "%s.__doc__ = _realsocket.%s.__doc__\n")

Modified: python/trunk/Lib/test/test_socket.py
==============================================================================
--- python/trunk/Lib/test/test_socket.py	(original)
+++ python/trunk/Lib/test/test_socket.py	Tue Mar 21 19:17:25 2006
@@ -469,12 +469,12 @@
         sock.close()
         self.assertRaises(socket.error, sock.send, "spam")
 
-    def testNewGetMethods(self):
-        # testing getfamily(), gettype() and getprotocol()
+    def testNewAttributes(self):
+        # testing .family, .type and .protocol
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self.assertEqual(sock.getfamily(), socket.AF_INET)
-        self.assertEqual(sock.gettype(), socket.SOCK_STREAM)
-        self.assertEqual(sock.getproto(), 0)
+        self.assertEqual(sock.family, socket.AF_INET)
+        self.assertEqual(sock.type, socket.SOCK_STREAM)
+        self.assertEqual(sock.proto, 0)
         sock.close()
 
 class BasicTCPTest(SocketConnectedTest):


More information about the Python-checkins mailing list