3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

apply_modes: fix statekeeping with current modes mapping

This commit is contained in:
James Lu 2019-08-23 00:22:25 -07:00
parent 46f081e19b
commit 6ad34672d3
2 changed files with 7 additions and 4 deletions

View File

@ -1054,10 +1054,12 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
# for example, someone sets mode "+l 30" on a channel already set "+l 25". # for example, someone sets mode "+l 30" on a channel already set "+l 25".
log.debug('(%s) Old modes for mode %r exist in %s, removing them: %s', log.debug('(%s) Old modes for mode %r exist in %s, removing them: %s',
self.name, real_mode, modelist, str(existing)) self.name, real_mode, modelist, str(existing))
for oldvalue in existing: while existing:
oldvalue = existing.pop()
modelist.discard((real_mode[0], oldvalue)) modelist.discard((real_mode[0], oldvalue))
modelist.add(real_mode) modelist.add(real_mode)
mapping[real_mode[0]].add(real_mode[1])
else: # Removing a mode else: # Removing a mode
log.debug('(%s) Removing mode %r from %s', self.name, real_mode, modelist) log.debug('(%s) Removing mode %r from %s', self.name, real_mode, modelist)
@ -1067,7 +1069,8 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
# If no args were needed on removal, remove all modes with that letter # If no args were needed on removal, remove all modes with that letter
# If an arg was given, remove all modes matching the arg (IRC case insensitive) # If an arg was given, remove all modes matching the arg (IRC case insensitive)
if existing is not None: if existing is not None:
for oldvalue in existing: while existing:
oldvalue = existing.pop()
if arg is None or self.to_lower(arg) == self.to_lower(oldvalue): if arg is None or self.to_lower(arg) == self.to_lower(oldvalue):
modelist.discard((real_mode[0], oldvalue)) modelist.discard((real_mode[0], oldvalue))
log.debug('(%s) Final modelist: %s', self.name, modelist) log.debug('(%s) Final modelist: %s', self.name, modelist)

View File

@ -509,7 +509,7 @@ class BaseProtocolTest(unittest.TestCase):
self.p.apply_modes('#Magic', [('+b', '*!*@example.net'), ('-b', '*!*@example.net')]) self.p.apply_modes('#Magic', [('+b', '*!*@example.net'), ('-b', '*!*@example.net')])
self.assertEqual(c.modes, set(), "Ban should have been removed (same case)") self.assertEqual(c.modes, set(), "Ban should have been removed (same case)")
self.p.apply_modes('#Magic', [('+b', '*!*@example.net'), ('+i', None), ('-b', '*!*@Example.net')]) self.p.apply_modes('#Magic', [('+b', '*!*@example.net'), ('-b', '*!*@Example.net')])
self.assertEqual(c.modes, set(), "Ban should have been removed (different case)") self.assertEqual(c.modes, set(), "Ban should have been removed (different case)")
u = self._make_user('nick', uid='user') u = self._make_user('nick', uid='user')
@ -572,7 +572,7 @@ class BaseProtocolTest(unittest.TestCase):
self.assertEqual(u.modes, {('i', None), ('w', None)}) self.assertEqual(u.modes, {('i', None), ('w', None)})
# TODO: test type coersion if channel or mode targets are ints # TODO: test type coersion if channel or mode targets are ints
# TODO: check the output of parse_modes() here too
def test_parse_apply_channel_key(self): def test_parse_apply_channel_key(self):
# Test /mode #channel -k * => /mode #channel -k PASSWORD coersion in parse_modes() # Test /mode #channel -k * => /mode #channel -k PASSWORD coersion in parse_modes()
# Note: strangely enough, the coersion is actually in parse_modes() as a special case # Note: strangely enough, the coersion is actually in parse_modes() as a special case