diff options
author | Georg Brandl <georg@python.org> | 2006-03-17 19:17:34 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-03-17 19:17:34 (GMT) |
commit | bc45a3f8210213986e12dfecd7c12b8a45b4f16b (patch) | |
tree | 290112e792ae1587f3c2db552975f8e06de05d4c /Lib | |
parent | 5c170fd4a9d2bc2e475d718cbbce526cad4a3eaa (diff) | |
download | cpython-bc45a3f8210213986e12dfecd7c12b8a45b4f16b.zip cpython-bc45a3f8210213986e12dfecd7c12b8a45b4f16b.tar.gz cpython-bc45a3f8210213986e12dfecd7c12b8a45b4f16b.tar.bz2 |
RFE #567972: Socket objects' family, type and proto properties are
now exposed via new get...() methods.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/socket.py | 18 | ||||
-rw-r--r-- | Lib/test/test_socket.py | 8 |
2 files changed, 26 insertions, 0 deletions
diff --git a/Lib/socket.py b/Lib/socket.py index ee2457f..3dc59c4 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -183,6 +183,24 @@ class _socketobject(object): 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 + _s = ("def %s(self, *args): return self._sock.%s(*args)\n\n" "%s.__doc__ = _realsocket.%s.__doc__\n") for _m in _socketmethods: diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 1899e78..5a851fc 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -469,6 +469,14 @@ class GeneralModuleTests(unittest.TestCase): sock.close() self.assertRaises(socket.error, sock.send, "spam") + def testNewGetMethods(self): + # testing getfamily(), gettype() and getprotocol() + 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) + sock.close() + class BasicTCPTest(SocketConnectedTest): def __init__(self, methodName='runTest'): |