Allow states to cleanly accept **kwargs

This addition makes it so that ALL data in the low state chunk is passed
to the state function via **kwargs. This means that by passing a
**kwargs from states all the back to a module function will allow for
very transparent additions of arguments to states that accept **kwargs
This commit is contained in:
Thomas S Hatch 2012-02-28 16:29:21 -07:00
parent 6a80f56a77
commit de8011adb2

View File

@ -405,6 +405,14 @@ class State(object):
arglen = len(aspec[0])
if isinstance(aspec[3], tuple):
deflen = len(aspec[3])
if aspec[2]:
# This state accepts kwargs
ret['kwargs'] = {}
for key in data:
# Passing kwargs the conflict with args == stack trace
if key in aspec[0]:
continue
ret['kwargs'][key] = data[key]
kwargs = {}
for ind in range(arglen - 1, 0, -1):
minus = arglen - ind
@ -573,7 +581,10 @@ class State(object):
if 'provider' in data:
self.load_modules(data)
cdata = self.format_call(data)
ret = self.states[cdata['full']](*cdata['args'])
if 'kwargs' in cdata:
ret = self.states[cdata['full']](*cdata['args'], **cdata['kwargs'])
else:
ret = self.states[cdata['full']](*cdata['args'])
ret['__run_num__'] = self.__run_num
self.__run_num += 1
format_log(ret)