mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Update socket.py to 3.14.5 (#7866)
* Update `socket.py` to 3.14.5 * Don't have socket.sethostname on android * Mark failing test
This commit is contained in:
1 parent
986550e519
commit
fcfb47d11b
3 files changed
+48
-16
No files matched your search
Vendored
+16
-12
@@ -640,18 +640,22 @@ def _fallback_socketpair(family=AF_INET, type=SOCK_STREAM, proto=0):
|
||||
# Authenticating avoids using a connection from something else
|
||||
# able to connect to {host}:{port} instead of us.
|
||||
# We expect only AF_INET and AF_INET6 families.
|
||||
try:
|
||||
if (
|
||||
ssock.getsockname() != csock.getpeername()
|
||||
or csock.getsockname() != ssock.getpeername()
|
||||
):
|
||||
raise ConnectionError("Unexpected peer connection")
|
||||
except:
|
||||
# getsockname() and getpeername() can fail
|
||||
# if either socket isn't connected.
|
||||
ssock.close()
|
||||
csock.close()
|
||||
raise
|
||||
#
|
||||
# Note that we skip this on WASI because on that platorm the client socket
|
||||
# may not have finished connecting by the time we've reached this point (gh-146139).
|
||||
if sys.platform != "wasi":
|
||||
try:
|
||||
if (
|
||||
ssock.getsockname() != csock.getpeername()
|
||||
or csock.getsockname() != ssock.getpeername()
|
||||
):
|
||||
raise ConnectionError("Unexpected peer connection")
|
||||
except:
|
||||
# getsockname() and getpeername() can fail
|
||||
# if either socket isn't connected.
|
||||
ssock.close()
|
||||
csock.close()
|
||||
raise
|
||||
|
||||
return (ssock, csock)
|
||||
|
||||
|
||||
Vendored
+31
-3
@@ -561,8 +561,8 @@ class ThreadedRDSSocketTest(SocketRDSTest, ThreadableTest):
|
||||
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
|
||||
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
|
||||
'VSOCK sockets required for this test.')
|
||||
@unittest.skipUnless(get_cid() != 2, # VMADDR_CID_HOST
|
||||
"This test can only be run on a virtual guest.")
|
||||
@unittest.skipIf(get_cid() == getattr(socket, 'VMADDR_CID_HOST', 2),
|
||||
"This test can only be run on a virtual guest.")
|
||||
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
|
||||
|
||||
def __init__(self, methodName='runTest'):
|
||||
@@ -572,7 +572,16 @@ class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
|
||||
def setUp(self):
|
||||
self.serv = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
|
||||
self.addCleanup(self.serv.close)
|
||||
self.serv.bind((socket.VMADDR_CID_ANY, VSOCKPORT))
|
||||
cid = get_cid()
|
||||
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
|
||||
cid = socket.VMADDR_CID_LOCAL
|
||||
try:
|
||||
self.serv.bind((cid, VSOCKPORT))
|
||||
except OSError as exc:
|
||||
if exc.errno == errno.EADDRNOTAVAIL:
|
||||
self.skipTest(f"bind() failed with {exc!r}")
|
||||
else:
|
||||
raise
|
||||
self.serv.listen()
|
||||
self.serverExplicitReady()
|
||||
self.serv.settimeout(support.LOOPBACK_TIMEOUT)
|
||||
@@ -2180,6 +2189,25 @@ class GeneralModuleTests(unittest.TestCase):
|
||||
source=_socket)
|
||||
enum._test_simple_enum(CheckedAddressInfo, socket.AddressInfo)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: Expected type 'int' but 'Mut' found
|
||||
@unittest.skipUnless(hasattr(socket.socket, "sendmsg"),"sendmsg not supported")
|
||||
def test_sendmsg_reentrant_ancillary_mutation(self):
|
||||
|
||||
class Mut:
|
||||
def __index__(self):
|
||||
seq.clear()
|
||||
return socket.SCM_RIGHTS
|
||||
|
||||
seq = [
|
||||
(socket.SOL_SOCKET, Mut(), b'xxxx'),
|
||||
(socket.SOL_SOCKET, socket.SCM_RIGHTS, b'xxxx'),
|
||||
]
|
||||
|
||||
left, right = socket.socketpair()
|
||||
self.addCleanup(left.close)
|
||||
self.addCleanup(right.close)
|
||||
self.assertRaises(OSError, left.sendmsg, [b'x'], seq)
|
||||
|
||||
|
||||
@unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.')
|
||||
class BasicCANTest(unittest.TestCase):
|
||||
|
||||
@@ -2652,7 +2652,7 @@ mod _socket {
|
||||
.map_err(|err| vm.new_os_error(err.into_string().unwrap()))
|
||||
}
|
||||
|
||||
#[cfg(all(unix, not(target_os = "redox")))]
|
||||
#[cfg(all(unix, not(any(target_os = "redox", target_os = "android"))))]
|
||||
#[pyfunction]
|
||||
fn sethostname(hostname: PyUtf8StrRef) -> nix::Result<()> {
|
||||
nix::unistd::sethostname(hostname.as_str())
|
||||
|
||||
Reference in new issue
Block a user