Removing dicttoxml dependency

This commit is contained in:
Jack Danger 2017-10-02 13:35:53 -07:00
parent fd134034fa
commit 867fc3b7f7
2 changed files with 21 additions and 3 deletions

View File

@ -2,7 +2,8 @@ from __future__ import unicode_literals
import json
import dicttoxml
import xmltodict
from jinja2 import Template
from six import iteritems
@ -26,6 +27,24 @@ def convert_json_error_to_xml(json_error):
return template.render(code=code, message=message)
def itemize(data):
"""
The xmltodict.unparse requires we modify the shape of the input dictionary slightly. Instead of a dict of the form:
{'key': ['value1', 'value2']}
We must provide:
{'key': {'item': ['value1', 'value2']}}
"""
if isinstance(data, dict):
ret = {}
for key in data:
ret[key] = itemize(data[key])
return ret
elif isinstance(data, list):
return {'item': [itemize(value) for value in data]}
else:
return data
class RedshiftResponse(BaseResponse):
@property
@ -36,7 +55,7 @@ class RedshiftResponse(BaseResponse):
if self.request_json:
return json.dumps(response)
else:
xml = dicttoxml.dicttoxml(response, attr_type=False, root=False)
xml = xmltodict.unparse(itemize(response), full_document=False)
return xml.decode("utf-8")
def call_action(self):

View File

@ -13,7 +13,6 @@ install_requires = [
"cryptography>=2.0.0",
"requests>=2.5",
"xmltodict",
"dicttoxml",
"six>1.9",
"werkzeug",
"pyaml",