Merge pull request #412 from JackDandy/feature/UpdateXmltodict

Update xmltodict library 0.9.0 to 0.9.2 (579a005).
This commit is contained in:
JackDandy 2015-06-14 00:10:37 +01:00
commit 89b36d31f9
2 changed files with 16 additions and 9 deletions

View file

@ -41,6 +41,7 @@
* Change check_url function to use requests instead of httplib library
* Update Six compatibility library 1.5.2 to 1.9.0 (8a545f4)
* Update SimpleJSON library 2.0.9 to 3.7.3 (0bcdf20)
* Update xmltodict library 0.9.0 to 0.9.2 (579a005)
[develop changelog]
* Update Requests library 2.7.0 (ab1f493) to 2.7.0 (8b5e457)

View file

@ -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:
raise ValueError('document with multiple roots')
for v in value:
for index, v in enumerate(value):
if full_document and depth == 0 and index > 0:
raise ValueError('document with multiple roots')
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: