def test_parse_parameter_prefix_order_parser(): """Ensure PREFIX order is maintained through parser. https://modern.ircdocs.horse/#prefix-parameter """ key, value = isupport.parse_parameter('PREFIX=(qov)~@+') assert value == (('q', '~'), ('o', '@'), ('v', '+'))
def test_parse_parameter_prefix_order_property(): """Ensure PREFIX order is maintained in property.""" instance = isupport.ISupport() key, value = isupport.parse_parameter('PREFIX=(qov)~@+') new = instance.apply(prefix=value, ) assert new.PREFIX == OrderedDict((('q', '~'), ('o', '@'), ('v', '+'))) assert tuple(new.PREFIX.keys()) == ('q', 'o', 'v')
def handle_isupport(bot, trigger): """Handle ``RPL_ISUPPORT`` events.""" parameters = {} for arg in trigger.args: try: key, value = isupport.parse_parameter(arg) parameters[key] = value except ValueError: # ignore malformed parameter: log a warning and continue LOGGER.warning('Unable to parse ISUPPORT parameter: %r', arg) bot._isupport = bot._isupport.apply(**parameters)
def test_parse_parameter_prefix_invalid_format(): with pytest.raises(ValueError): isupport.parse_parameter('PREFIX=ov@+') with pytest.raises(ValueError): isupport.parse_parameter('PREFIX=(ov)@') with pytest.raises(ValueError): isupport.parse_parameter('PREFIX=(o)@+')
def handle_isupport(bot, trigger): """Handle ``RPL_ISUPPORT`` events.""" # remember if certain actionable tokens are known to be supported, # before parsing RPL_ISUPPORT botmode_support = 'BOT' in bot.isupport namesx_support = 'NAMESX' in bot.isupport uhnames_support = 'UHNAMES' in bot.isupport # parse ISUPPORT message from server parameters = {} for arg in trigger.args: try: key, value = isupport.parse_parameter(arg) parameters[key] = value except ValueError: # ignore malformed parameter: log a warning and continue LOGGER.warning("Unable to parse ISUPPORT parameter: %r", arg) bot._isupport = bot._isupport.apply(**parameters) # was BOT mode support status updated? if not botmode_support and 'BOT' in bot.isupport: # yes it was! set our mode unless the config overrides it botmode = bot.isupport['BOT'] if botmode not in bot.config.core.modes: bot.write(('MODE', bot.nick, '+' + botmode)) # was NAMESX support status updated? if not namesx_support and 'NAMESX' in bot.isupport: # yes it was! if 'multi-prefix' not in bot.server_capabilities: # and the server doesn't have the multi-prefix capability # so we can ask the server to use the NAMESX feature bot.write(('PROTOCTL', 'NAMESX')) # was UHNAMES support status updated? if not uhnames_support and 'UHNAMES' in bot.isupport: # yes it was! if 'userhost-in-names' not in bot.server_capabilities: # and the server doesn't have the userhost-in-names capability # so we should ask for UHNAMES instead bot.write(('PROTOCTL', 'UHNAMES'))
def handle_isupport(bot, trigger): """Handle ``RPL_ISUPPORT`` events.""" # remember if NAMESX is known to be supported, before parsing RPL_ISUPPORT namesx_support = 'NAMESX' in bot.isupport # parse ISUPPORT message from server parameters = {} for arg in trigger.args: try: key, value = isupport.parse_parameter(arg) parameters[key] = value except ValueError: # ignore malformed parameter: log a warning and continue LOGGER.warning('Unable to parse ISUPPORT parameter: %r', arg) bot._isupport = bot._isupport.apply(**parameters) # was NAMESX support status updated? if not namesx_support and 'NAMESX' in bot.isupport: # yes it was! if 'multi-prefix' not in bot.server_capabilities: # and the server doesn't have the multi-prefix capability # so we can ask the server to use the NAMESX feature bot.write(('PROTOCTL', 'NAMESX'))
def test_parse_parameter_maxlist_many(): key, value = isupport.parse_parameter('MAXLIST=b:60,e:40,I:50') assert key == 'MAXLIST' assert value == (('I', 50), ('b', 60), ('e', 40))
def test_parse_parameter_maxlist(): key, value = isupport.parse_parameter('MAXLIST=beI:25') assert key == 'MAXLIST' assert value == (('beI', 25), )
def test_parse_parameter_removed(arg): key, value = isupport.parse_parameter(arg) assert value is None assert key == arg
def test_parse_parameter_targmax_optional(): key, value = isupport.parse_parameter('TARGMAX=') assert key == 'TARGMAX' assert value == tuple()
def test_parse_parameter_targmax_many(): key, value = isupport.parse_parameter('TARGMAX=PRIVMSG:3,WHOIS:1') assert key == 'TARGMAX' assert value == (('PRIVMSG', 3), ('WHOIS', 1))
def test_parse_parameter_chanmode_raise(): with pytest.raises(ValueError): isupport.parse_parameter('CHANMODES=b,k,l')
def test_parse_parameter_maxlist_invalid(): with pytest.raises(ValueError): isupport.parse_parameter('MAXLIST=b:60,e,I:50')
def test_parse_parameter_chanmode(): key, value = isupport.parse_parameter('CHANMODES=b,k,l,imnpst') assert key == 'CHANMODES' assert value == ('b', 'k', 'l', 'imnpst', tuple())
def test_parse_parameter_chanmode_extra_many(): key, value = isupport.parse_parameter('CHANMODES=b,k,l,imnpst,bkl,imnpst') assert key == 'CHANMODES' assert value == ('b', 'k', 'l', 'imnpst', ('bkl', 'imnpst'))
def test_parse_parameter_chanlimit_limit_optional(): key, value = isupport.parse_parameter('CHANLIMIT=#:50,$:10,~:') assert key == 'CHANLIMIT' assert value == (('#', 50), ('$', 10), ('~', None))
def test_parse_parameter_chanlimit_many(): key, value = isupport.parse_parameter('CHANLIMIT=#:50,$:10') assert key == 'CHANLIMIT' assert value == (('#', 50), ('$', 10))
def test_parse_parameter_chanlimit_single(): key, value = isupport.parse_parameter('CHANLIMIT=#:50') assert key == 'CHANLIMIT' assert value == (('#', 50), )
def test_parse_parameter_maxlist_many_mixed(): key, value = isupport.parse_parameter('MAXLIST=beI:25,Z:10') assert key == 'MAXLIST' assert value == (('Z', 10), ('beI', 25))
def test_parse_parameter_elist(): key, value = isupport.parse_parameter('ELIST=C') assert key == 'ELIST' assert value == ('C', )
def test_parse_parameter_maxlist_many_mixed_override(): key, value = isupport.parse_parameter('MAXLIST=b:10,beI:25,Z:10,I:40') assert key == 'MAXLIST' assert value == (('I', 40), ('Z', 10), ('b', 10), ('beI', 25))
def test_parse_parameter_elist_many_sorted(): key, value = isupport.parse_parameter('ELIST=MTCUN') assert key == 'ELIST' assert value == ('C', 'M', 'N', 'T', 'U')
def test_parse_parameter_prefix(): key, value = isupport.parse_parameter('PREFIX=(ov)@+') assert key == 'PREFIX' assert value == (('o', '@'), ('v', '+'))
def test_parse_parameter_no_value(arg, expected): key, value = isupport.parse_parameter(arg) assert (key, value) == expected
def test_parse_parameter_targmax(): key, value = isupport.parse_parameter('TARGMAX=PRIVMSG:3') assert key == 'TARGMAX' assert value == (('PRIVMSG', 3), )
def test_parse_parameter_extban_no_prefix(): key, value = isupport.parse_parameter('EXTBAN=,ABCNOcjmp') assert key == 'EXTBAN' assert value == (None, ('A', 'B', 'C', 'N', 'O', 'c', 'j', 'm', 'p'))
def test_parse_parameter_targmax_many_optional(): key, value = isupport.parse_parameter('TARGMAX=PRIVMSG:3,JOIN:,WHOIS:1') assert key == 'TARGMAX' assert value == (('JOIN', None), ('PRIVMSG', 3), ('WHOIS', 1))
def test_parse_parameter_extban_invalid(): with pytest.raises(ValueError): isupport.parse_parameter('EXTBAN=ABCNOcjmp')
def test_parse_parameter_extban(): key, value = isupport.parse_parameter('EXTBAN=~,qjncrRa') assert key == 'EXTBAN' assert value == ('~', ('R', 'a', 'c', 'j', 'n', 'q', 'r'))
def test_parse_parameter_single_letter_raise(arg): with pytest.raises(ValueError): isupport.parse_parameter(arg)