mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-06 17:44:09 +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
|
# These are the characters valid in a token. Everything printable except
|
||||||
# double-quote, left-bracket, and right-bracket.
|
# 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=''):
|
def __init__(self, tokens=''):
|
||||||
|
# Add a '|' to tokens to have the pipe syntax.
|
||||||
self.validChars = self.validChars.translate(string.ascii, tokens)
|
self.validChars = self.validChars.translate(string.ascii, tokens)
|
||||||
|
|
||||||
def handleToken(self, token):
|
def handleToken(self, token):
|
||||||
@ -256,7 +257,11 @@ def tokenize(s):
|
|||||||
"""A utility function to create a Tokenizer and tokenize a string."""
|
"""A utility function to create a Tokenizer and tokenize a string."""
|
||||||
start = time.time()
|
start = time.time()
|
||||||
try:
|
try:
|
||||||
args = Tokenizer().tokenize(s)
|
if conf.enablePipeSyntax:
|
||||||
|
tokens = '|'
|
||||||
|
else:
|
||||||
|
tokens = ''
|
||||||
|
args = Tokenizer(tokens).tokenize(s)
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
raise SyntaxError, str(e)
|
raise SyntaxError, str(e)
|
||||||
debug.msg('tokenize took %s seconds.' % (time.time() - start), 'verbose')
|
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
|
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
|
# defaultCapabilities: Capabilities allowed to everyone by default. You almost
|
||||||
# certainly want to have !owner and !admin in here.
|
# certainly want to have !owner and !admin in here.
|
||||||
|
@ -82,15 +82,23 @@ class TokenizerTestCase(unittest.TestCase):
|
|||||||
self.assertRaises(SyntaxError, tokenize, '"foo') #"
|
self.assertRaises(SyntaxError, tokenize, '"foo') #"
|
||||||
|
|
||||||
def testPipe(self):
|
def testPipe(self):
|
||||||
self.assertRaises(SyntaxError, tokenize, '| foo')
|
try:
|
||||||
self.assertRaises(SyntaxError, tokenize, 'foo ||bar')
|
conf.enablePipeSyntax = True
|
||||||
self.assertRaises(SyntaxError, tokenize, 'bar |')
|
self.assertRaises(SyntaxError, tokenize, '| foo')
|
||||||
self.assertEqual(tokenize('foo | bar'), ['bar', ['foo']])
|
self.assertRaises(SyntaxError, tokenize, 'foo ||bar')
|
||||||
self.assertEqual(tokenize('foo | bar | baz'), ['baz', ['bar',['foo']]])
|
self.assertRaises(SyntaxError, tokenize, 'bar |')
|
||||||
self.assertEqual(tokenize('foo bar | baz'), ['baz', ['foo', 'bar']])
|
self.assertEqual(tokenize('foo | bar'), ['bar', ['foo']])
|
||||||
self.assertEqual(tokenize('foo | bar baz'), ['bar', 'baz', ['foo']])
|
self.assertEqual(tokenize('foo | bar | baz'),
|
||||||
self.assertEqual(tokenize('foo bar | baz quux'),
|
['baz', ['bar',['foo']]])
|
||||||
['baz', 'quux', ['foo', 'bar']])
|
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):
|
class FunctionsTestCase(unittest.TestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user