asynchat + asyncore: Python 3 compatibility#1402
Conversation
2a1779f to
fc89800
Compare
JelleZijlstra
left a comment
There was a problem hiding this comment.
The changes look good, but I left a few suggestions for further improvement.
| def found_terminator(self) -> None: ... | ||
| def set_terminator(self, term: Union[str, int, None]) -> None: ... | ||
| def get_terminator(self) -> Union[str, int, None]: ... | ||
| def set_terminator(self, term: Union[bytes, int, None]) -> None: ... |
There was a problem hiding this comment.
From the code it looks like this also supports str in (at least) 3.6, if self.use_encoding is true. I'm not sure when use_encoding would be True though, and it's undocumented.
There was a problem hiding this comment.
That flag would have to be set by the client of this code. I'm pretty sure that no one ever has set it, nor ever will – it's broken in at least three different ways, possibly four.
| @@ -87,22 +89,22 @@ class dispatcher: | |||
|
|
|||
| # return type is an address | |||
| def recvfrom(self, bufsize: int, flags: int = ...) -> Any: ... | |||
There was a problem hiding this comment.
This method and recvfrom_into don't actually exist directly but are inherited from the underlying socket object through a __getattr__ (I was confused for a while).
| def sendto(self, data: str, address: Union[tuple, str], flags: int = ...) -> int: ... | ||
| def recvfrom_into(self, buffer: bytes, nbytes: int, flags: int = ...) -> Any: ... | ||
| def recv_into(self, buffer: bytes, nbytes: int, flags: int = ...) -> Any: ... | ||
| def send(self, data: bytes, flags: int = ...) -> Optional[int]: ... |
There was a problem hiding this comment.
In 3.6, the flags argument doesn't seem to exist and I don't think the return type is Optional.
Includes an update to smtpd, which uses asynchat.
fc89800 to
308ede0
Compare
| def accept(self) -> Optional[Tuple[socket.socket, Any]]: ... | ||
| def recv(self, buffer_size: int) -> str: ... | ||
| def log(self, message: Any) -> None: ... | ||
| def send(self, data: bytes) -> int: ... |
There was a problem hiding this comment.
To reply to the now-concealed comment (sorry about that!): it looks like this was always the correct signature for dispatcher's send – flags never existed here, only in socket, and as far as I can tell the return type was never Optional.
Convert various
strtobytes; add missingdispatcher.close()method.