Open cuu508 opened 2 weeks ago
This is a little tricky than I thought :-)
aiosmtpd can listen on IPv4 address, on IPv6 address (by using aiosmtpd.controller.Controller
), and to an UNIX socket (by using aiosmtpd.controller.UnixSocketController
). The type of Session.peer is different in each case:
tuple[str, int]
(hostname, port)tuple[str, int, int, int]
, (hostname, port, flowinfo, scope_id)str
(not sure what it is supposed to return, in practice when testing locally with swaks as the client, I got an empty string back) So the combined type annotation would be something like
tuple[str, int] | tuple[str, int, int, int] | str | None
Or, in Python 3.8 compatible syntax:
Union[Tuple[str, int], Tuple[str, int, int, int], str, None]
The type annotation for Session.peer is currently:
This attribute appears to be set in
connection_made()
like so:Where transport is an instance of
asyncio.BaseTransport
.Looking at BaseTransport docs,
get_extra_info("peername")
callssocket.getpeername()
and returns the result.For IPv4 sockets at least,
socket.getpeername()
seems to return anip-address,port
tuple. So I think a more accurate annotation for Session.peer would be something liketuple[str, int] | None
.