mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Make sure state.channel is carried over when we call State.essence. Also,
add continueOnError option to any().
This commit is contained in:
parent
01513bcb95
commit
c87788dc62
@ -671,13 +671,24 @@ class optional(additional):
|
|||||||
setDefault(state, self.default)
|
setDefault(state, self.default)
|
||||||
|
|
||||||
class any(context):
|
class any(context):
|
||||||
|
def __init__(self, spec, continueOnError=False):
|
||||||
|
self.__parent = super(any, self)
|
||||||
|
self.__parent.__init__(spec)
|
||||||
|
self.continueOnError = continueOnError
|
||||||
|
|
||||||
def __call__(self, irc, msg, args, state):
|
def __call__(self, irc, msg, args, state):
|
||||||
st = state.essence()
|
st = state.essence()
|
||||||
try:
|
try:
|
||||||
while args:
|
while args:
|
||||||
super(any, self).__call__(irc, msg, args, st)
|
self.__parent.__call__(irc, msg, args, st)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
except (callbacks.ArgumentError, callbacks.Error), e:
|
||||||
|
if not self.continueOnError:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
log.debug('Got %s, returning default.', utils.exnToString(e))
|
||||||
|
pass
|
||||||
state.args.append(st.args)
|
state.args.append(st.args)
|
||||||
|
|
||||||
class many(any):
|
class many(any):
|
||||||
@ -781,7 +792,7 @@ class State(object):
|
|||||||
def essence(self):
|
def essence(self):
|
||||||
st = State(self.types)
|
st = State(self.types)
|
||||||
for (attr, value) in self.__dict__.iteritems():
|
for (attr, value) in self.__dict__.iteritems():
|
||||||
if attr not in ('args', 'kwargs', 'channel'):
|
if attr not in ('args', 'kwargs'):
|
||||||
setattr(st, attr, value)
|
setattr(st, attr, value)
|
||||||
return st
|
return st
|
||||||
|
|
||||||
|
@ -92,6 +92,8 @@ class CommandsTestCase(SupyTestCase):
|
|||||||
self.assertState([any('int')], ['1', '2', '3'], [[1, 2, 3]])
|
self.assertState([any('int')], ['1', '2', '3'], [[1, 2, 3]])
|
||||||
self.assertState([None, any('int')], ['1', '2', '3'], ['1', [2, 3]])
|
self.assertState([None, any('int')], ['1', '2', '3'], ['1', [2, 3]])
|
||||||
self.assertState([any('int')], [], [[]])
|
self.assertState([any('int')], [], [[]])
|
||||||
|
self.assertState([any('int', continueOnError=True), 'text'],
|
||||||
|
['1', '2', 'test'], [[1, 2], 'test'])
|
||||||
|
|
||||||
def testMany(self):
|
def testMany(self):
|
||||||
spec = [many('int')]
|
spec = [many('int')]
|
||||||
|
Loading…
Reference in New Issue
Block a user