diff --git a/src/irclib.py b/src/irclib.py index 701dd1fb9..8396d5c86 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -821,6 +821,27 @@ class IrcState(IrcCommandDispatcher, log.Firewalled): return batches + def getClientTagDenied(self, tag): + """Returns whether the given tag is denied by the server, according + to its CLIENTTAGDENY policy. + This is only informative, and servers may still allow or deny tags + at their discretion. + + For details, see the RPL_ISUPPORT section in + + """ + tag = tag.lstrip("+") + + denied_tags = self.supported.get('CLIENTTAGDENY') + if not denied_tags: + return False + denied_tags = denied_tags.split(',') + if '*' in denied_tags: + # All tags are denied by default, check the whitelist + return ('-' + tag) not in denied_tags + else: + return tag in denied_tags + def do004(self, irc, msg): """Handles parsing the 004 reply diff --git a/test/test_irclib.py b/test/test_irclib.py index 0d870e93b..4342cdfa3 100644 --- a/test/test_irclib.py +++ b/test/test_irclib.py @@ -420,6 +420,29 @@ class IrcStateTestCase(SupyTestCase): self.assertEqual(state.supported['chanmodes'], frozenset('biklmnopstveI')) + def testClientTagDenied(self): + state = irclib.IrcState() + + # By default, every tag is assumed allowed + self.assertEqual(state.getClientTagDenied('foo'), False) + self.assertEqual(state.getClientTagDenied('bar'), False) + + # Blacklist + state.addMsg(self.irc, ircmsgs.IrcMsg( + ':example.org 005 mybot CLIENTTAGDENY=foo :are supported by this server')) + self.assertEqual(state.getClientTagDenied('foo'), True) + self.assertEqual(state.getClientTagDenied('bar'), False) + self.assertEqual(state.getClientTagDenied('+foo'), True) + self.assertEqual(state.getClientTagDenied('+bar'), False) + + # Whitelist + state.addMsg(self.irc, ircmsgs.IrcMsg( + ':example.org 005 mybot CLIENTTAGDENY=*,-foo :are supported by this server')) + self.assertEqual(state.getClientTagDenied('foo'), False) + self.assertEqual(state.getClientTagDenied('bar'), True) + self.assertEqual(state.getClientTagDenied('+foo'), False) + self.assertEqual(state.getClientTagDenied('+bar'), True) + def testShort004(self): state = irclib.IrcState() state.addMsg(self.irc, ircmsgs.IrcMsg(':coulomb.oftc.net 004 testnick coulomb.oftc.net hybrid-7.2.2+oftc1.6.8'))