Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4265854

Browse filesBrowse files
pythongh-132987: Support __index__() in the socket module (pythonGH-133093)
ntohl(), htonl(), if_indextoname(), getaddrinfo() now use __index__() if available. Also fix the Argument Clinic names for module-level functions (although this does not affect the user).
1 parent c33efa8 commit 4265854
Copy full SHA for 4265854

File tree

3 files changed

+263
-200
lines changed
Filter options

3 files changed

+263
-200
lines changed

‎Lib/test/test_socket.py

Copy file name to clipboardExpand all lines: Lib/test/test_socket.py
+9-10Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ def testInterfaceNameIndex(self):
11691169
@support.skip_android_selinux('if_indextoname')
11701170
def testInvalidInterfaceIndexToName(self):
11711171
self.assertRaises(OSError, socket.if_indextoname, 0)
1172-
self.assertRaises(OverflowError, socket.if_indextoname, -1)
1172+
self.assertRaises(ValueError, socket.if_indextoname, -1)
11731173
self.assertRaises(OverflowError, socket.if_indextoname, 2**1000)
11741174
self.assertRaises(TypeError, socket.if_indextoname, '_DEADBEEF')
11751175
if hasattr(socket, 'if_nameindex'):
@@ -1225,24 +1225,23 @@ def testNtoH(self):
12251225
self.assertEqual(swapped & mask, mask)
12261226
self.assertRaises(OverflowError, func, 1<<34)
12271227

1228-
@support.cpython_only
1229-
@unittest.skipIf(_testcapi is None, "requires _testcapi")
12301228
def testNtoHErrors(self):
1231-
import _testcapi
12321229
s_good_values = [0, 1, 2, 0xffff]
12331230
l_good_values = s_good_values + [0xffffffff]
1234-
l_bad_values = [-1, -2, 1<<32, 1<<1000]
1235-
s_bad_values = (
1236-
l_bad_values +
1237-
[_testcapi.INT_MIN-1, _testcapi.INT_MAX+1] +
1238-
[1 << 16, _testcapi.INT_MAX]
1239-
)
1231+
neg_values = [-1, -2, -(1<<15)-1, -(1<<31)-1, -(1<<63)-1, -1<<1000]
1232+
l_bad_values = [1<<32, 1<<1000]
1233+
s_bad_values = l_bad_values + [1 << 16, (1<<31)-1, 1<<31]
12401234
for k in s_good_values:
12411235
socket.ntohs(k)
12421236
socket.htons(k)
12431237
for k in l_good_values:
12441238
socket.ntohl(k)
12451239
socket.htonl(k)
1240+
for k in neg_values:
1241+
self.assertRaises(ValueError, socket.ntohs, k)
1242+
self.assertRaises(ValueError, socket.htons, k)
1243+
self.assertRaises(ValueError, socket.ntohl, k)
1244+
self.assertRaises(ValueError, socket.htonl, k)
12461245
for k in s_bad_values:
12471246
self.assertRaises(OverflowError, socket.ntohs, k)
12481247
self.assertRaises(OverflowError, socket.htons, k)

‎Modules/clinic/socketmodule.c.h

Copy file name to clipboardExpand all lines: Modules/clinic/socketmodule.c.h
+135-48Lines changed: 135 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.