Revert "port format_all to salt-api pending updates in salt core"

This reverts commit bc3d492791.

These changes are now in Salt core.

Conflicts:
	saltapi/__init__.py
This commit is contained in:
Seth House 2012-11-15 10:59:20 -07:00
parent 385530b967
commit 4d98d72cd7

View File

@ -35,7 +35,7 @@ class APIClient(object):
raise SaltException('No client specified')
l_fun = getattr(self, low['client'])
f_call = format_call(l_fun, low)
f_call = salt.utils.format_call(l_fun, low)
ret = l_fun(*f_call.get('args', ()), **f_call.get('kwargs', {}))
return ret
@ -61,64 +61,3 @@ class APIClient(object):
kwargs['fun'] = fun
wheel = salt.wheel.Wheel(self.opts)
return wheel.master_call(**kwargs)
### Remove when salt 0.10.5 is released!
def _getargs(func):
'''
A small wrapper around getargspec that also supports callable classes
'''
if not callable(func):
raise TypeError('{0} is not a callable'.format(func))
if inspect.isfunction(func):
aspec = inspect.getargspec(func)
elif inspect.ismethod(func):
aspec = inspect.getargspec(func)
del aspec.args[0] # self
elif isinstance(func, object):
aspec = inspect.getargspec(func.__call__)
del aspec.args[0] # self
else:
raise TypeError("Cannot inspect argument list for '{0}'".format(func))
return aspec
def format_call(fun, data):
'''
Pass in a function and a dict containing arguments to the function.
A dict with the keys args and kwargs is returned
'''
ret = {}
ret['args'] = []
aspec = _getargs(fun)
arglen = 0
deflen = 0
if isinstance(aspec.args, list):
arglen = len(aspec.args)
if isinstance(aspec.defaults, tuple):
deflen = len(aspec.defaults)
if aspec.keywords:
# This state accepts kwargs
ret['kwargs'] = {}
for key in data:
# Passing kwargs the conflict with args == stack trace
if key in aspec.args:
continue
ret['kwargs'][key] = data[key]
kwargs = {}
for ind in range(arglen - 1, 0, -1):
minus = arglen - ind
if deflen - minus > -1:
kwargs[aspec.args[ind]] = aspec.defaults[-minus]
for arg in kwargs:
if arg in data:
kwargs[arg] = data[arg]
for arg in aspec.args:
if arg in kwargs:
ret['args'].append(kwargs[arg])
else:
ret['args'].append(data[arg])
return ret