diff options
author | Georg Brandl <georg@python.org> | 2006-03-21 18:17:25 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-03-21 18:17:25 (GMT) |
commit | bb03ac0dae9830968ae971ab53143e2d539d7a3a (patch) | |
tree | cb6f196ec6c3933a1b064e500cbf81355566c5c7 /Lib | |
parent | 9ca8789ee39880199990ed964b6af0369c4294c1 (diff) | |
download | cpython-bb03ac0dae9830968ae971ab53143e2d539d7a3a.zip cpython-bb03ac0dae9830968ae971ab53143e2d539d7a3a.tar.gz cpython-bb03ac0dae9830968ae971ab53143e2d539d7a3a.tar.bz2 |
Correct API design mistake from rev. 43126: make socket attributes readonly properties.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/socket.py | 22 | ||||
-rw-r--r-- | Lib/test/test_socket.py | 10 |
2 files changed, 9 insertions, 23 deletions
diff --git a/Lib/socket.py b/Lib/socket.py index 3dc59c4..7e49192 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -182,24 +182,10 @@ class _socketobject(object): 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") diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 5a851fc..592e897 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -469,12 +469,12 @@ class GeneralModuleTests(unittest.TestCase): 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): |