Skip to content

Commit

Permalink
Feat/cleanup and deprecation fix (#78)
Browse files Browse the repository at this point in the history
* 🎨 feat: run black on the dicttoxml

* fix: issue with Deprecation with Python3.10

DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working

* ⬆️ feat: use latest python3.10-rc2
  • Loading branch information
vinitkumar authored Sep 10, 2021
1 parent ff1351a commit f6fd690
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, pypy3, '3.10.0-rc.1']
python-version: [3.6, 3.7, 3.8, 3.9, pypy3, '3.10.0-rc.2']
os: [
ubuntu-20.04,
macOS-latest,
Expand Down
62 changes: 49 additions & 13 deletions json2xml/dicttoxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_xml_type(val):
return "null"
if isinstance(val, dict):
return "dict"
if isinstance(val, collections.Iterable):
if isinstance(val, collections.abc.Iterable):
return "list"
return type(val).__name__

Expand Down Expand Up @@ -159,7 +159,7 @@ def convert(obj, ids, attr_type, item_func, cdata, item_wrap, parent="root"):
if isinstance(obj, dict):
return convert_dict(obj, ids, parent, attr_type, item_func, cdata, item_wrap)

if isinstance(obj, collections.Iterable):
if isinstance(obj, collections.abc.Iterable):
return convert_list(obj, ids, parent, attr_type, item_func, cdata, item_wrap)

raise TypeError("Unsupported data type: %s (%s)" % (obj, type(obj).__name__))
Expand Down Expand Up @@ -206,7 +206,7 @@ def convert_dict(obj, ids, parent, attr_type, item_func, cdata, item_wrap):
)
)

elif isinstance(val, collections.Iterable):
elif isinstance(val, collections.abc.Iterable):
if attr_type:
attr["type"] = get_xml_type(val)
addline(
Expand Down Expand Up @@ -258,48 +258,82 @@ def convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap):

elif isinstance(item, dict):
if not attr_type:
if (item_wrap):
if item_wrap:
addline(
"<%s>%s</%s>"
% (
item_name,
convert_dict(item, ids, parent, attr_type, item_func, cdata, item_wrap),
convert_dict(
item,
ids,
parent,
attr_type,
item_func,
cdata,
item_wrap,
),
item_name,
)
)
else:
addline(
"%s"
% (
convert_dict(item, ids, parent, attr_type, item_func, cdata, item_wrap),
convert_dict(
item,
ids,
parent,
attr_type,
item_func,
cdata,
item_wrap,
),
)
)
else:
if (item_wrap):
if item_wrap:
addline(
'<%s type="dict">%s</%s>'
% (
item_name,
convert_dict(item, ids, parent, attr_type, item_func, cdata, item_wrap),
convert_dict(
item,
ids,
parent,
attr_type,
item_func,
cdata,
item_wrap,
),
item_name,
)
)
else:
addline(
'%s'
"%s"
% (
convert_dict(item, ids, parent, attr_type, item_func, cdata, item_wrap),
convert_dict(
item,
ids,
parent,
attr_type,
item_func,
cdata,
item_wrap,
),
)
)

elif isinstance(item, collections.Iterable):
elif isinstance(item, collections.abc.Iterable):
if not attr_type:
addline(
"<%s %s>%s</%s>"
% (
item_name,
make_attrstring(attr),
convert_list(item, ids, item_name, attr_type, item_func, cdata, item_wrap),
convert_list(
item, ids, item_name, attr_type, item_func, cdata, item_wrap
),
item_name,
)
)
Expand All @@ -309,7 +343,9 @@ def convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap):
% (
item_name,
make_attrstring(attr),
convert_list(item, ids, item_name, attr_type, item_func, cdata, item_wrap),
convert_list(
item, ids, item_name, attr_type, item_func, cdata, item_wrap
),
item_name,
)
)
Expand Down

0 comments on commit f6fd690

Please sign in to comment.