Private GIT

Skip to content
Snippets Groups Projects
Commit 4b0584d1 authored by Dustyn Gibson's avatar Dustyn Gibson
Browse files

Revert "Revert "Update xmltodict to v 0.9.2""

This reverts commit 1c280eb6.
parent 8ac1b2dd
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ except NameError: # pragma no cover
_unicode = str
__author__ = 'Martin Blech'
__version__ = '0.9.0'
__version__ = '0.9.2'
__license__ = 'MIT'
......@@ -94,7 +94,7 @@ class _DictSAXHandler(object):
self.stack.append((self.item, self.data))
if self.xml_attribs:
attrs = self.dict_constructor(
(self.attr_prefix+key, value)
(self.attr_prefix+self._build_name(key), value)
for (key, value) in attrs.items())
else:
attrs = None
......@@ -256,17 +256,20 @@ def _emit(key, value, content_handler,
preprocessor=None,
pretty=False,
newl='\n',
indent='\t'):
indent='\t',
full_document=True):
if preprocessor is not None:
result = preprocessor(key, value)
if result is None:
return
key, value = result
if not isinstance(value, (list, tuple)):
if (not hasattr(value, '__iter__')
or isinstance(value, _basestring)
or isinstance(value, dict)):
value = [value]
if depth == 0 and len(value) > 1:
for index, v in enumerate(value):
if full_document and depth == 0 and index > 0:
raise ValueError('document with multiple roots')
for v in value:
if v is None:
v = OrderedDict()
elif not isinstance(v, dict):
......@@ -318,7 +321,8 @@ def unparse(input_dict, output=None, encoding='utf-8', full_document=True,
can be customized with the `newl` and `indent` parameters.
"""
((key, value),) = input_dict.items()
if full_document and len(input_dict) != 1:
raise ValueError('Document must have exactly one root.')
must_return = False
if output is None:
output = StringIO()
......@@ -326,7 +330,9 @@ def unparse(input_dict, output=None, encoding='utf-8', full_document=True,
content_handler = XMLGenerator(output, encoding)
if full_document:
content_handler.startDocument()
_emit(key, value, content_handler, **kwargs)
for key, value in input_dict.items():
_emit(key, value, content_handler, full_document=full_document,
**kwargs)
if full_document:
content_handler.endDocument()
if must_return:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment