Skip to content

Commit e36cd99

Browse files
authored
Update socket.py to 3.14.5 (RustPython#7866)
* Update `socket.py` to 3.14.5 * Don't have socket.sethostname on android * Mark failing test
1 parent 7ebffd0 commit e36cd99

3 files changed

Lines changed: 48 additions & 16 deletions

File tree

Lib/socket.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -640,18 +640,22 @@ def _fallback_socketpair(family=AF_INET, type=SOCK_STREAM, proto=0):
640640
# Authenticating avoids using a connection from something else
641641
# able to connect to {host}:{port} instead of us.
642642
# We expect only AF_INET and AF_INET6 families.
643-
try:
644-
if (
645-
ssock.getsockname() != csock.getpeername()
646-
or csock.getsockname() != ssock.getpeername()
647-
):
648-
raise ConnectionError("Unexpected peer connection")
649-
except:
650-
# getsockname() and getpeername() can fail
651-
# if either socket isn't connected.
652-
ssock.close()
653-
csock.close()
654-
raise
643+
#
644+
# Note that we skip this on WASI because on that platorm the client socket
645+
# may not have finished connecting by the time we've reached this point (gh-146139).
646+
if sys.platform != "wasi":
647+
try:
648+
if (
649+
ssock.getsockname() != csock.getpeername()
650+
or csock.getsockname() != ssock.getpeername()
651+
):
652+
raise ConnectionError("Unexpected peer connection")
653+
except:
654+
# getsockname() and getpeername() can fail
655+
# if either socket isn't connected.
656+
ssock.close()
657+
csock.close()
658+
raise
655659

656660
return (ssock, csock)
657661

Lib/test/test_socket.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ def clientTearDown(self):
561561
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
562562
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
563563
'VSOCK sockets required for this test.')
564-
@unittest.skipUnless(get_cid() != 2, # VMADDR_CID_HOST
565-
"This test can only be run on a virtual guest.")
564+
@unittest.skipIf(get_cid() == getattr(socket, 'VMADDR_CID_HOST', 2),
565+
"This test can only be run on a virtual guest.")
566566
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
567567

568568
def __init__(self, methodName='runTest'):
@@ -572,7 +572,16 @@ def __init__(self, methodName='runTest'):
572572
def setUp(self):
573573
self.serv = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
574574
self.addCleanup(self.serv.close)
575-
self.serv.bind((socket.VMADDR_CID_ANY, VSOCKPORT))
575+
cid = get_cid()
576+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
577+
cid = socket.VMADDR_CID_LOCAL
578+
try:
579+
self.serv.bind((cid, VSOCKPORT))
580+
except OSError as exc:
581+
if exc.errno == errno.EADDRNOTAVAIL:
582+
self.skipTest(f"bind() failed with {exc!r}")
583+
else:
584+
raise
576585
self.serv.listen()
577586
self.serverExplicitReady()
578587
self.serv.settimeout(support.LOOPBACK_TIMEOUT)
@@ -2180,6 +2189,25 @@ def test_addressinfo_enum(self):
21802189
source=_socket)
21812190
enum._test_simple_enum(CheckedAddressInfo, socket.AddressInfo)
21822191

2192+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: Expected type 'int' but 'Mut' found
2193+
@unittest.skipUnless(hasattr(socket.socket, "sendmsg"),"sendmsg not supported")
2194+
def test_sendmsg_reentrant_ancillary_mutation(self):
2195+
2196+
class Mut:
2197+
def __index__(self):
2198+
seq.clear()
2199+
return socket.SCM_RIGHTS
2200+
2201+
seq = [
2202+
(socket.SOL_SOCKET, Mut(), b'xxxx'),
2203+
(socket.SOL_SOCKET, socket.SCM_RIGHTS, b'xxxx'),
2204+
]
2205+
2206+
left, right = socket.socketpair()
2207+
self.addCleanup(left.close)
2208+
self.addCleanup(right.close)
2209+
self.assertRaises(OSError, left.sendmsg, [b'x'], seq)
2210+
21832211

21842212
@unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.')
21852213
class BasicCANTest(unittest.TestCase):

crates/stdlib/src/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ mod _socket {
26522652
.map_err(|err| vm.new_os_error(err.into_string().unwrap()))
26532653
}
26542654

2655-
#[cfg(all(unix, not(target_os = "redox")))]
2655+
#[cfg(all(unix, not(any(target_os = "redox", target_os = "android"))))]
26562656
#[pyfunction]
26572657
fn sethostname(hostname: PyUtf8StrRef) -> nix::Result<()> {
26582658
nix::unistd::sethostname(hostname.as_str())

0 commit comments

Comments
 (0)