From 55ee0fe8336bad8d5fa5801757f47dc70c7ec639 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Fri, 26 Aug 2022 22:57:21 -0700 Subject: [PATCH] [BACKEND] Use native xml library, remove dicttoxml --- setup.cfg | 1 - src/ytdl_sub/utils/xml.py | 16 ++++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/setup.cfg b/setup.cfg index 744893a2..58715f1c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,7 +26,6 @@ packages=find: install_requires = yt-dlp argparse==1.4.0 - dicttoxml==1.7.4 mergedeep==1.3.4 mediafile==0.9.0 PyYAML==6.0 diff --git a/src/ytdl_sub/utils/xml.py b/src/ytdl_sub/utils/xml.py index 98248a4b..5ae0f5dc 100644 --- a/src/ytdl_sub/utils/xml.py +++ b/src/ytdl_sub/utils/xml.py @@ -1,6 +1,6 @@ from typing import Dict -import dicttoxml +import xml.etree.ElementTree as et def _to_max_3_byte_utf8_char(char: str) -> str: @@ -38,7 +38,7 @@ def to_max_3_byte_utf8_dict(string_dict: Dict[str, str]) -> Dict[str, str]: } -def to_xml(nfo_dict: Dict[str, str], nfo_root: str) -> bytes: +def to_xml(nfo_dict: Dict[str, str], nfo_root: str) -> str: """ Transforms a dict to XML @@ -53,9 +53,9 @@ def to_xml(nfo_dict: Dict[str, str], nfo_root: str) -> bytes: ------- XML bytes """ - return dicttoxml.dicttoxml( - obj=nfo_dict, - root=True, - custom_root=nfo_root, - attr_type=False, - ) + xml_root = et.Element(nfo_root) + for key, value in nfo_dict.items(): + et.SubElement(xml_root, value) + + return et.tostring(element=xml_root, encoding='utf-8', xml_declaration=True) +