Skip to content

Commit

Permalink
pylint, mypy: fix warnings re: OS-specific import.
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierog committed Nov 24, 2024
1 parent e325ca3 commit 272ce58
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/moulti/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 272ce58

Please sign in to comment.