Skip to content

Commit

Permalink
Fix flake8 errors, bump up version and add release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
sanand0 committed May 9, 2017
1 parent d68db48 commit c41f5f4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
12 changes: 12 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
History
-------

0.1.8 (9 May 2017)
~~~~~~~~~~~~~~~~~~

- Add Abdera_ and Cobra_ conventions
- Add ``Parker.data(preserve_root=True)`` option to preserve root element in
Parker convention.

Thanks to @dagwieers

.. _Abdera: http://wiki.open311.org/JSON_and_XML_Conversion/#the-abdera-convention
.. _Cobra: http://wiki.open311.org/JSON_and_XML_Conversion/#the-cobra-convention

0.1.6 (18 Feb 2016)
~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 3 additions & 2 deletions tests/test_xmljson.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def test_data(self):
eq = self.check_data(xmljson.abdera)

# Dicts
eq('{"x": {"a": {}}}',
eq('{"x": {"a": {}}}',
'<x><a/></x>')
eq('{"x": {"attributes": {"x": 1}}}',
'<x x="1"/>')
Expand Down Expand Up @@ -607,7 +607,8 @@ def test_data(self):
'<x><a/></x>')
eq('{"x": {"attributes": {"x": "1"}}}',
'<x x="1"/>')
eq('{"root": {"attributes": {}, "children": [{"x": {"attributes": {"x": "1"}}}, {"y": {"attributes": {}, "children": [{"z": {"attributes": {}}}]}}]}}',
eq('{"root": {"attributes": {}, "children": [{"x": {"attributes": {"x": "1"}}},'
+ ' {"y": {"attributes": {}, "children": [{"z": {"attributes": {}}}]}}]}}',
'<root><x x="1"/><y><z/></y></root>')

# Attributes
Expand Down
17 changes: 11 additions & 6 deletions xmljson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

__author__ = 'S Anand'
__email__ = 'root.node@gmail.com'
__version__ = '0.1.7'
__version__ = '0.1.8'

# Python 3: define unicode() as str()
if sys.version_info[0] == 3:
Expand Down Expand Up @@ -220,12 +220,14 @@ def data(self, root):
if self.simple_text and len(children) == len(root.attrib) == 0:
value = self._fromstring(text)
else:
children_list = [ self._fromstring(text), ]
children_list = [self._fromstring(text), ]

count = Counter(child.tag for child in children)
for child in children:
child_data = self.data(child)
if count[child.tag] == 1 and len(children_list) > 1 and isinstance(children_list[-1], types.DictType):
if (count[child.tag] == 1
and len(children_list) > 1
and isinstance(children_list[-1], dict)):
# Merge keys to existing dictionary
children_list[-1].update(child_data)
else:
Expand All @@ -248,7 +250,8 @@ def data(self, root):
class Cobra(XMLData):
'''Converts between XML and data using the Cobra convention'''
def __init__(self, **kwargs):
super(Cobra, self).__init__(simple_text=True, text_content=True, xml_fromstring=False, **kwargs)
super(Cobra, self).__init__(simple_text=True, text_content=True,
xml_fromstring=False, **kwargs)

def data(self, root):
'''Convert etree.Element into a dictionary'''
Expand All @@ -272,12 +275,14 @@ def data(self, root):
if self.simple_text and len(children) == len(root.attrib) == 0:
value = self._fromstring(text)
else:
children_list = [ self._fromstring(text), ]
children_list = [self._fromstring(text), ]

count = Counter(child.tag for child in children)
for child in children:
child_data = self.data(child)
if count[child.tag] == 1 and len(children_list) > 1 and isinstance(children_list[-1], types.DictType):
if (count[child.tag] == 1
and len(children_list) > 1
and isinstance(children_list[-1], dict)):
# Merge keys to existing dictionary
children_list[-1].update(child_data)
else:
Expand Down

0 comments on commit c41f5f4

Please sign in to comment.