From 272ce58d7d97cc59936de9eb3737322efdbc55dc Mon Sep 17 00:00:00 2001 From: "Xavier G." Date: Sat, 23 Nov 2024 23:08:21 +0100 Subject: [PATCH] pylint, mypy: fix warnings re: OS-specific import. --- src/moulti/protocol.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/moulti/protocol.py b/src/moulti/protocol.py index bb3bea0..bedd0cd 100644 --- a/src/moulti/protocol.py +++ b/src/moulti/protocol.py @@ -119,12 +119,14 @@ def clean_socket(socket_path: str = PRINTABLE_MOULTI_SOCKET) -> None: pass def get_unix_credentials(socket: Socket) -> tuple[int, int, int]: - # struct ucred is { pid_t, uid_t, gid_t } - struct_ucred = '3i' - from socket import SO_PEERCRED # pylint: disable=import-outside-toplevel - unix_credentials = socket.getsockopt(SOL_SOCKET, SO_PEERCRED, calcsize(struct_ucred)) - pid, uid, gid = unpack(struct_ucred, unix_credentials) - return pid, uid, gid + if sys.platform == 'linux': + # struct ucred is { pid_t, uid_t, gid_t } + struct_ucred = '3i' + from socket import SO_PEERCRED # pylint: disable=import-outside-toplevel,no-name-in-module + unix_credentials = socket.getsockopt(SOL_SOCKET, SO_PEERCRED, calcsize(struct_ucred)) + pid, uid, gid = unpack(struct_ucred, unix_credentials) + return pid, uid, gid + return -1, -1, -1 def moulti_connect(address: str = MOULTI_SOCKET, bind: str | None = None) -> Socket: client_socket = moulti_unix_socket()