summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2004-06-28 00:50:43 (GMT)
committerBarry Warsaw <barry@python.org>2004-06-28 00:50:43 (GMT)
commit11b91a0ea33fc4632a84d1b762f432411f9a0ddd (patch)
tree9727062871138ce674455ee6c021220361bd8ccb /Lib/test/test_socket.py
parent1ed5705154d6a0f4e23345f3ead902d2fffecca8 (diff)
downloadcpython-11b91a0ea33fc4632a84d1b762f432411f9a0ddd.zip
cpython-11b91a0ea33fc4632a84d1b762f432411f9a0ddd.tar.gz
cpython-11b91a0ea33fc4632a84d1b762f432411f9a0ddd.tar.bz2
Added socket.getservbyport(), and make its second argument and that of
getservbyname() optional. Update the tests and the docs.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 6e2f80c..2831454 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -284,22 +284,34 @@ class GeneralModuleTests(unittest.TestCase):
self.assertEqual(swapped & mask, mask)
self.assertRaises(OverflowError, func, 1L<<34)
- def testGetServByName(self):
- # Testing getservbyname()
- # try a few protocols - not everyone has telnet enabled
- for proto in ("telnet", "ssh", "www", "ftp"):
+ def testGetServBy(self):
+ eq = self.assertEqual
+ # Find one service that exists, then check all the related interfaces.
+ # I've ordered this by protocols that have both a tcp and udp
+ # protocol, at least for modern Linuxes.
+ for service in ('ssh', 'www', 'echo', 'imap2'):
try:
- socket.getservbyname(proto, 'tcp')
- break
- except socket.error:
- pass
- try:
- socket.getservbyname(proto, 'udp')
+ port = socket.getservbyname(service, 'tcp')
break
except socket.error:
pass
else:
raise socket.error
+ # Try same call with optional protocol omitted
+ port2 = socket.getservbyname(service)
+ eq(port, port2)
+ # Try udp, but don't barf it it doesn't exist
+ try:
+ udpport = socket.getservbyname(service, 'udp')
+ except socket.error:
+ udpport = None
+ else:
+ eq(udpport, port)
+ # Now make sure the lookup by port returns the same service name
+ eq(socket.getservbyport(port2), service)
+ eq(socket.getservbyport(port, 'tcp'), service)
+ if udpport is not None:
+ eq(socket.getservbyport(udpport, 'udp'), service)
def testDefaultTimeout(self):
# Testing default timeout