home · contact · privacy
Further tighten msg parsing.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 19 Aug 2025 00:54:50 +0000 (02:54 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 19 Aug 2025 00:54:50 +0000 (02:54 +0200)
ircplom/client.py

index 8bce64a70e0c2b4bced4954c0c265bdce863b5f9..27931bd5792cdc9766ab964261ad636ca28b3879 100644 (file)
@@ -42,6 +42,7 @@ class _MsgParseExpectation(NamedTuple):
     len_min_params: int = 0
     len_max_params: int = 0
     params: tuple[str, ...] = tuple()
+    source: Optional[str] = None
 
 
 _EXPECTATIONS: dict[str, _MsgParseExpectation] = {
@@ -56,15 +57,15 @@ _EXPECTATIONS: dict[str, _MsgParseExpectation] = {
    '900': _MsgParseExpectation(4),
    '903': _MsgParseExpectation(2),
    '904': _MsgParseExpectation(2),
-   'AUTHENTICATE': _MsgParseExpectation(params=('+',)),
+   'AUTHENTICATE': _MsgParseExpectation(params=('+',), source=''),
    'CAP': _MsgParseExpectation(3, 15),
-   'ERROR': _MsgParseExpectation(1),
+   'ERROR': _MsgParseExpectation(1, source=''),
    'JOIN': _MsgParseExpectation(1),
    'MODE': _MsgParseExpectation(2),
    'NICK': _MsgParseExpectation(1),
    'NOTICE': _MsgParseExpectation(2),
    'PART': _MsgParseExpectation(1, 2),
-   'PING': _MsgParseExpectation(1),
+   'PING': _MsgParseExpectation(1, source=''),
    'PRIVMSG': _MsgParseExpectation(2),
 }
 
@@ -77,6 +78,8 @@ class _IrcMsg(IrcMessage):
         if not verb == self.verb:
             return False
         expect = _EXPECTATIONS[verb]
+        if expect.source is not None and self.source != expect.source:
+            return False
         if expect.params:
             return self.params == expect.params
         n_msg_params = len(self.params)