Added configuration variable to determine whether pipe syntax is accepted.

This commit is contained in:
Jeremy Fincher 2003-09-17 19:19:38 +00:00
parent 1c99146f41
commit 70b80f0622
3 changed files with 45 additions and 11 deletions

View File

@ -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')

View File

@ -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.

View File

@ -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):