From c8de1e81559f7cd3c391d516337ad095580e58cb Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 1 Dec 2003 21:59:01 +0000 Subject: [PATCH] Made the string of flags that require an argument an optional argument so you can parse the flags for some other purpose. --- src/ircutils.py | 13 +++++++++---- test/test_ircutils.py | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ircutils.py b/src/ircutils.py index c9ad596b1..3dc0643ec 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -161,8 +161,7 @@ def banmask(hostmask): else: return '*!*@' + host -_argModes = 'ovhblkqe' -def separateModes(args): +def separateModes(args, requireArguments='ovhblkqe'): """Separates modelines into single mode change tuples. Basically, you should give it the .args of a MODE IrcMsg. @@ -180,6 +179,9 @@ def separateModes(args): >>> separateModes(['+sntl', '100']) [('+s', None), ('+n', None), ('+t', None), ('+l', '100')] """ + if not requireArguments: + if not isinstance(args, list): + args = [args] modes = args[0] assert modes[0] in '+-', 'Invalid args: %r' % args args = list(args[1:]) @@ -191,12 +193,15 @@ def separateModes(args): last = modes[index] index += 1 else: - if modes[index] in _argModes: + if modes[index] in requireArguments: ret.append((last + modes[index], args.pop(0))) else: ret.append((last + modes[index], None)) index += 1 - return ret + if not requireArguments: # Special case + return [x for (x, y) in ret] + else: + 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 e59f7dd78..ef6ab3292 100644 --- a/test/test_ircutils.py +++ b/test/test_ircutils.py @@ -143,6 +143,12 @@ 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('[]\\~'))