Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions json2xml/dicttoxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numbers
from collections.abc import Callable, Sequence
from random import SystemRandom
from typing import Any, Dict, Union
from typing import Any, Union

from defusedxml.minidom import parseString

Expand Down Expand Up @@ -505,10 +505,12 @@ def convert_kv(
key: str,
val: str | numbers.Number,
attr_type: bool,
attr: dict[str, Any] = {},
attr: dict[str, Any] | None = None,
cdata: bool = False,
) -> str:
"""Converts a number or string into an XML element"""
if attr is None:
attr = {}
key, attr = make_valid_xml_name(key, attr)

if attr_type:
Expand All @@ -518,9 +520,11 @@ def convert_kv(


def convert_bool(
key: str, val: bool, attr_type: bool, attr: dict[str, Any] = {}, cdata: bool = False
key: str, val: bool, attr_type: bool, attr: dict[str, Any] | None = None, cdata: bool = False
) -> str:
"""Converts a boolean into an XML element"""
if attr is None:
attr = {}
key, attr = make_valid_xml_name(key, attr)

if attr_type:
Expand All @@ -530,9 +534,11 @@ def convert_bool(


def convert_none(
key: str, attr_type: bool, attr: dict[str, Any] = {}, cdata: bool = False
key: str, attr_type: bool, attr: dict[str, Any] | None = None, cdata: bool = False
) -> str:
"""Converts a null value into an XML element"""
if attr is None:
attr = {}
key, attr = make_valid_xml_name(key, attr)

if attr_type:
Expand Down Expand Up @@ -669,6 +675,8 @@ def dicttoxml(
<list a="b" c="d"><item>4</item><item>5</item><item>6</item></list>

"""
if xml_namespaces is None:
xml_namespaces = {}
output = []
namespace_str = ""
for prefix in xml_namespaces:
Expand Down
2 changes: 1 addition & 1 deletion json2xml/json2xml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pyexpat import ExpatError
from typing import Any, Dict, Optional
from typing import Any

from defusedxml.minidom import parseString

Expand Down
1 change: 0 additions & 1 deletion json2xml/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Utility methods for converting XML data to dictionary from various sources."""
import json
from typing import Dict, Optional

import urllib3

Expand Down
Loading