diff --git a/src/callbacks.py b/src/callbacks.py index 5c4b1bba1..29a241d0b 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -195,8 +195,9 @@ class Tokenizer: # # These are the characters valid in a token. Everything printable except # double-quote, left-bracket, and right-bracket. - validChars = string.ascii[33:].translate(string.ascii, '"[]|') + validChars = string.ascii[33:].translate(string.ascii, '"[]') def __init__(self, tokens=''): + # Add a '|' to tokens to have the pipe syntax. self.validChars = self.validChars.translate(string.ascii, tokens) def handleToken(self, token): @@ -256,7 +257,11 @@ def tokenize(s): """A utility function to create a Tokenizer and tokenize a string.""" start = time.time() try: - args = Tokenizer().tokenize(s) + if conf.enablePipeSyntax: + tokens = '|' + else: + tokens = '' + args = Tokenizer(tokens).tokenize(s) except ValueError, e: raise SyntaxError, str(e) debug.msg('tokenize took %s seconds.' % (time.time() - start), 'verbose') diff --git a/src/conf.py b/src/conf.py index 972f77c7e..1377526c6 100644 --- a/src/conf.py +++ b/src/conf.py @@ -91,6 +91,27 @@ allowEval = False ### replyWhenNotCommand = True +### +# requireRegistration: Oftentimes a plugin will want to record who added or +# changed or messed with it last. Supybot's user database +# is an excellent way to determine who exactly someone is. +# You may, however, want something a little less +# "intrustive," so you can set this variable to False to +# tell such plugins that they should use the hostmask when +# the user isn't registered with the user database. +### +requireRegistration = False + +### +# enablePipeSyntax: Supybot allows nested commands; generally, commands are +# nested via [square brackets]. Supybot can also use a +# syntax more similar to Unix pipes. What would be (and +# still can be; the pipe syntax doesn't disable the bracket +# syntax) "bot: bar [foo]" can now by "bot: foo | bar" +# This variable enables such syntax. +### +enablePipeSyntax = False + ### # defaultCapabilities: Capabilities allowed to everyone by default. You almost # certainly want to have !owner and !admin in here. diff --git a/test/test_callbacks.py b/test/test_callbacks.py index d95448465..ab09ed5e9 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -82,15 +82,23 @@ class TokenizerTestCase(unittest.TestCase): self.assertRaises(SyntaxError, tokenize, '"foo') #" def testPipe(self): - self.assertRaises(SyntaxError, tokenize, '| foo') - self.assertRaises(SyntaxError, tokenize, 'foo ||bar') - self.assertRaises(SyntaxError, tokenize, 'bar |') - self.assertEqual(tokenize('foo | bar'), ['bar', ['foo']]) - self.assertEqual(tokenize('foo | bar | baz'), ['baz', ['bar',['foo']]]) - self.assertEqual(tokenize('foo bar | baz'), ['baz', ['foo', 'bar']]) - self.assertEqual(tokenize('foo | bar baz'), ['bar', 'baz', ['foo']]) - self.assertEqual(tokenize('foo bar | baz quux'), - ['baz', 'quux', ['foo', 'bar']]) + try: + conf.enablePipeSyntax = True + self.assertRaises(SyntaxError, tokenize, '| foo') + self.assertRaises(SyntaxError, tokenize, 'foo ||bar') + self.assertRaises(SyntaxError, tokenize, 'bar |') + self.assertEqual(tokenize('foo | bar'), ['bar', ['foo']]) + self.assertEqual(tokenize('foo | bar | baz'), + ['baz', ['bar',['foo']]]) + self.assertEqual(tokenize('foo bar | baz'), + ['baz', ['foo', 'bar']]) + self.assertEqual(tokenize('foo | bar baz'), + ['bar', 'baz', ['foo']]) + self.assertEqual(tokenize('foo bar | baz quux'), + ['baz', 'quux', ['foo', 'bar']]) + finally: + conf.enablePipeSyntax = False + class FunctionsTestCase(unittest.TestCase):