diff --git a/src/ircutils.py b/src/ircutils.py index 49eafa33d..657b12366 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -198,7 +198,9 @@ def banmask(hostmask): else: return '*!*@' + host -def separateModes(args, requireArguments='ovhblkqe'): +_plusRequireArguments = 'ovhblkqe' +_minusRequireArguments = 'ocvbkqe' +def separateModes(args): """Separates modelines into single mode change tuples. Basically, you should give it the .args of a MODE IrcMsg. @@ -216,9 +218,8 @@ def separateModes(args, requireArguments='ovhblkqe'): >>> separateModes(['+sntl', '100']) [('+s', None), ('+n', None), ('+t', None), ('+l', '100')] """ - if not requireArguments: - if not isinstance(args, list): - args = [args] + if not args: + return [] modes = args[0] assert modes[0] in '+-', 'Invalid args: %r' % args args = list(args[1:]) @@ -230,15 +231,16 @@ def separateModes(args, requireArguments='ovhblkqe'): last = modes[index] index += 1 else: + if last == '+': + requireArguments = _plusRequireArguments + else: + requireArguments = _minusRequireArguments if modes[index] in requireArguments: ret.append((last + modes[index], args.pop(0))) else: ret.append((last + modes[index], None)) index += 1 - if not requireArguments: # Special case - return [x for (x, y) in ret] - else: - return ret + return ret def joinModes(modes): """Joins modes of the same form as returned by separateModes.""" diff --git a/test/test_ircutils.py b/test/test_ircutils.py index f13f16085..af4a3a97c 100644 --- a/test/test_ircutils.py +++ b/test/test_ircutils.py @@ -156,12 +156,6 @@ class FunctionsTestCase(unittest.TestCase): self.assertEqual(ircutils.separateModes(['+sntl', '100']), [('+s', None),('+n', None),('+t', None),('+l', '100')]) - def testSeparateModesWithoutRequireArguments(self): - self.assertEqual(ircutils.separateModes(['+oo-b'], ''), - ['+o', '+o', '-b']) - self.assertEqual(ircutils.separateModes('+oo-b', ''), - ['+o', '+o', '-b']) - def testToLower(self): self.assertEqual('jemfinch', ircutils.toLower('jemfinch')) self.assertEqual('{}|^', ircutils.toLower('[]\\~'))