mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 06:04:21 +01:00
Added configuration variable to determine whether pipe syntax is accepted.
This commit is contained in:
parent
1c99146f41
commit
70b80f0622
@ -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')
|
||||
|
21
src/conf.py
21
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.
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user