diff --git a/src/dbus_fast/auth.py b/src/dbus_fast/auth.py index c491980..09fa6f6 100644 --- a/src/dbus_fast/auth.py +++ b/src/dbus_fast/auth.py @@ -1,5 +1,6 @@ import enum import os +from typing import List, Tuple from .errors import AuthError @@ -11,7 +12,7 @@ from .errors import AuthError # doing that. I might just end up giving the raw socket and leaving it all up # to the user, but it would be nice to have a little guidance in the interface # since a lot of it is strongly specified. If you have a need for this, contact -# the project maintainer to help stabalize this interface. +# the project maintainer to help stabilize this interface. class _AuthResponse(enum.Enum): @@ -22,7 +23,7 @@ class _AuthResponse(enum.Enum): AGREE_UNIX_FD = "AGREE_UNIX_FD" @classmethod - def parse(klass, line): + def parse(klass, line: str) -> Tuple["_AuthResponse", List[str]]: args = line.split(" ") response = klass(args[0]) return response, args[1:] @@ -37,18 +38,18 @@ class Authenticator: :seealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol """ - def _authentication_start(self, negotiate_unix_fd=False): + def _authentication_start(self, negotiate_unix_fd: bool = False) -> str: raise NotImplementedError( "authentication_start() must be implemented in the inheriting class" ) - def _receive_line(self, line): + def _receive_line(self, line: str) -> str: raise NotImplementedError( "receive_line() must be implemented in the inheriting class" ) @staticmethod - def _format_line(line): + def _format_line(line: str) -> bytes: return f"{line}\r\n".encode() @@ -59,16 +60,16 @@ class AuthExternal(Authenticator): :sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol """ - def __init__(self): - self.negotiate_unix_fd = False - self.negotiating_fds = False + def __init__(self) -> None: + self.negotiate_unix_fd: bool = False + self.negotiating_fds: bool = False - def _authentication_start(self, negotiate_unix_fd=False) -> str: + def _authentication_start(self, negotiate_unix_fd: bool = False) -> str: self.negotiate_unix_fd = negotiate_unix_fd hex_uid = str(os.getuid()).encode().hex() return f"AUTH EXTERNAL {hex_uid}" - def _receive_line(self, line: str): + def _receive_line(self, line: str) -> str: response, args = _AuthResponse.parse(line) if response is _AuthResponse.OK: @@ -91,7 +92,7 @@ class AuthAnnonymous(Authenticator): :sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol """ - def _authentication_start(self, negotiate_unix_fd=False) -> str: + def _authentication_start(self, negotiate_unix_fd: bool = False) -> str: if negotiate_unix_fd: raise AuthError( "annonymous authentication does not support negotiating unix fds right now"