for easy use by plugins in :mod:`~hooke.plugin`.
"""
-def _kwargs(kwargs, arguments, translations={}):
+def _kwargs(kwargs, arguments, translations={}, argument_input_keys=False):
"""Split off kwargs for the arguments listed in arguments.
Also add the kwargs marked in `translations`.
>>> kwargs = {'param_a':1, 'param_b':2, 'param_c':3}
>>> args = [Argument(name='param a')]
>>> translations = {'the_big_c_param':'param_c'}
- >>> pprint.pprint(_kwargs(kwargs, args, translations))
+ >>> pprint.pprint(_kwargs(kwargs, args, translations,
+ ... argument_input_keys=False))
+ {'param_a': 1, 'the_big_c_param': 3}
+ >>> pprint.pprint(_kwargs(kwargs, args, translations,
+ ... argument_input_keys=True))
+ {'the_big_c_param': 3}
+ >>> kwargs = {'param a':1, 'param b':2, 'param c':3}
+ >>> translations = {'the_big_c_param':'param c'}
+ >>> pprint.pprint(_kwargs(kwargs, args, translations,
+ ... argument_input_keys=True))
{'param_a': 1, 'the_big_c_param': 3}
"""
+ arg_keys = [arg.name for arg in arguments]
keys = [arg.name.replace(' ', '_') for arg in arguments]
- ret = dict([(key, kwargs[key]) for key in keys])
+ ret = {}
+ for arg_key,key in zip(arg_keys, keys):
+ in_key = key
+ if argument_input_keys == True:
+ in_key = arg_key
+ if in_key in kwargs:
+ ret[key] = kwargs[in_key]
for target_key,source_key in translations.items():
if source_key in kwargs:
ret[target_key] = kwargs[source_key]