From: Christian Heller Date: Tue, 19 Aug 2025 10:25:01 +0000 (+0200) Subject: Refactor 903 and 904 into new system. X-Git-Url: https://plomlompom.com/repos/blog?a=commitdiff_plain;h=5526d0e0c86cb3fa394ad7a360c1c799e582b34f;p=ircplom Refactor 903 and 904 into new system. --- diff --git a/ircplom/client.py b/ircplom/client.py index b51ab90..e78c2e4 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -72,8 +72,10 @@ _EXPECTATIONS: tuple[_MsgParseExpectation, ...] = ( _MsgParseExpectation('432', 3, source=_MsgSource.SERVER), _MsgParseExpectation('433', 3, source=_MsgSource.SERVER), _MsgParseExpectation('900', 4, source=_MsgSource.SERVER), - _MsgParseExpectation('903', 2, source=_MsgSource.SERVER), - _MsgParseExpectation('904', 2, source=_MsgSource.SERVER), + _MsgParseExpectation('903', params=(_MsgParam.NICKNAME_ME, _MsgParam.ANY), + source=_MsgSource.SERVER), + _MsgParseExpectation('904', params=(_MsgParam.NICKNAME_ME, _MsgParam.ANY), + source=_MsgSource.SERVER), _MsgParseExpectation('AUTHENTICATE', params=('+',), source=_MsgSource.NONE), _MsgParseExpectation('CAP', 3, 15, source=_MsgSource.SERVER), _MsgParseExpectation('ERROR', params=(_MsgParam.ANY,), @@ -690,10 +692,10 @@ class Client(ABC, ClientQueueMixin): self._db.nickname, remainder = msg.params[1].split('!', maxsplit=1) self._db.username, self._db.client_host = remainder.split('@') self._db.sasl_account = msg.params[2] - elif self._match_msg(msg, '903')\ - or self._match_msg(msg, '904'): # RPL_SASLSUCCESS, … - self._db.sasl_auth_state = 'WIN' if msg.verb == '903' else 'FAIL' - self._caps.end_negotiation() # … or ERR_SASLFAIL + elif ((ret := self._match_msg(msg, '903')) # RPL_SASLSUCCESS + or (ret := self._match_msg(msg, '904'))): # ERR_SASLFAIL + self._db.sasl_auth_state = ret['any'] + self._caps.end_negotiation() elif self._match_msg(msg, 'AUTHENTICATE'): auth = b64encode((self._db.nick_wanted + '\0' + self._db.nick_wanted + '\0'