Private GIT

Skip to content
Snippets Groups Projects
Commit 1c280eb6 authored by Fernando's avatar Fernando
Browse files

Revert "Update xmltodict to v 0.9.2"

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