mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
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.
This commit is contained in:
parent
b8a690d42a
commit
c075e197d6
2 changed files with 64 additions and 15 deletions
|
@ -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'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue