Make sure state.channel is carried over when we call State.essence. Also,

add continueOnError option to any().
This commit is contained in:
James Vega 2004-11-30 05:15:41 +00:00
parent 01513bcb95
commit c87788dc62
2 changed files with 15 additions and 2 deletions

View File

@ -671,13 +671,24 @@ class optional(additional):
setDefault(state, self.default)
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):
st = state.essence()
try:
while args:
super(any, self).__call__(irc, msg, args, st)
self.__parent.__call__(irc, msg, args, st)
except IndexError:
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)
class many(any):
@ -781,7 +792,7 @@ class State(object):
def essence(self):
st = State(self.types)
for (attr, value) in self.__dict__.iteritems():
if attr not in ('args', 'kwargs', 'channel'):
if attr not in ('args', 'kwargs'):
setattr(st, attr, value)
return st

View File

@ -92,6 +92,8 @@ class CommandsTestCase(SupyTestCase):
self.assertState([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', continueOnError=True), 'text'],
['1', '2', 'test'], [[1, 2], 'test'])
def testMany(self):
spec = [many('int')]