diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-25 16:01:12 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-25 16:01:12 (GMT) |
commit | c075e197d6453939bce6253ebb4fdb5dffaeb6c7 (patch) | |
tree | d5d1de007ff4dd7a5d2b56aa8b4cedcab5a2c865 /Lib | |
parent | b8a690d42a2476eeb308cb379382a3337f3a3c07 (diff) | |
download | cpython-c075e197d6453939bce6253ebb4fdb5dffaeb6c7.zip cpython-c075e197d6453939bce6253ebb4fdb5dffaeb6c7.tar.gz cpython-c075e197d6453939bce6253ebb4fdb5dffaeb6c7.tar.bz2 |
Extended socket.htonl and ntohl to accept longs.
Fixes SF bug #568322.
The code should raise an OverflowError if the long is > 32 bits, even
on platforms where sizeof(long) > 4.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_socket.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 423df76..44b42ff 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -247,6 +247,17 @@ class GeneralModuleTests(unittest.TestCase): except socket.error: pass + def testNtoH(self): + def twice(f): + def g(x): + return f(f(x)) + return g + for i in (0, 1, 0xffff0000, 2L, (2**32L) - 1): + self.assertEqual(i, twice(socket.htonl)(i)) + self.assertEqual(i, twice(socket.ntohl)(i)) + self.assertRaises(OverflowError, socket.htonl, 2L**34) + self.assertRaises(OverflowError, socket.ntohl, 2L**34) + def testGetServByName(self): """Testing getservbyname().""" if hasattr(socket, 'getservbyname'): |