Revert "Moved fmt_lowdata into a module-level function"

This reverts commit 7a319e36c5.

Reformatting the POST data isn't really a content_type concern.

Conflicts:
	saltapi/netapi/rest_cherrypy/__init__.py
This commit is contained in:
Seth House 2012-11-15 09:54:33 -07:00
parent 6289b6bd8a
commit fa7867af13

View File

@ -34,28 +34,6 @@ def __virtual__():
return 'rest'
return False
def fmt_lowdata(data):
'''
Take CherryPy body data from a POST (et al) request and format it into
lowdata. It will accept repeated parameters and pair and format those
into multiple lowdata chunks.
'''
pairs = []
for k,v in data.items():
# Ensure parameter is a list
argl = v if isinstance(v, list) else [v]
# Make pairs of (key, value) from {key: [*value]}
pairs.append(zip([k] * len(argl), argl))
lowdata = []
for i in itertools.izip_longest(*pairs):
if not all(i):
msg = "Error pairing parameters: %s"
raise Exception(msg % str(i))
lowdata.append(dict(i))
return lowdata
def salt_auth_tool():
ignore_urls = ('/login',)
@ -121,7 +99,7 @@ cherrypy.tools.hypermedia_out = cherrypy.Tool('before_handler', hypermedia_out)
# Be liberal in what you accept
ct_in_map = {
'application/x-www-form-urlencoded': fmt_lowdata,
'application/x-www-form-urlencoded': cherrypy._cpreqbody.process_urlencoded,
'application/json': json.loads,
'application/x-yaml': yaml.load,
'text/yaml': yaml.load,
@ -148,6 +126,28 @@ class LowDataAdapter(object):
self.opts = opts
self.api = saltapi.APIClient(opts)
def fmt_lowdata(self, data):
'''
Take CherryPy body data from a POST (et al) request and format it into
lowdata. It will accept repeated parameters and pair and format those
into multiple lowdata chunks.
'''
pairs = []
for k,v in data.items():
# Ensure parameter is a list
argl = v if isinstance(v, list) else [v]
# Make pairs of (key, value) from {key: [*value]}
pairs.append(zip([k] * len(argl), argl))
lowdata = []
for i in itertools.izip_longest(*pairs):
if not all(i):
msg = "Error pairing parameters: %s"
raise Exception(msg % str(i))
lowdata.append(dict(i))
return lowdata
def exec_lowdata(self, lowdata):
'''
Pass lowdata to Salt to be executed