home · contact · privacy
Refactor 903 and 904 into new system.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 19 Aug 2025 10:25:01 +0000 (12:25 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 19 Aug 2025 10:25:01 +0000 (12:25 +0200)
ircplom/client.py

index b51ab904055029f6026dd58d255ce862b7a60fd5..e78c2e42e8968489f81c13d932a65a74d6a87219 100644 (file)
@@ -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'