From 149ba483eb1857b38abd0a60ccf05be289b839dc Mon Sep 17 00:00:00 2001 From: Josef Friedrich Date: Sun, 21 Jan 2024 10:45:32 +0100 Subject: [PATCH] Use XmlManipulator --- mscxyz/style.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mscxyz/style.py b/mscxyz/style.py index 96b8369..84e1d22 100644 --- a/mscxyz/style.py +++ b/mscxyz/style.py @@ -6,8 +6,6 @@ from pathlib import Path from typing import Optional, Sequence, TypedDict, Union, cast -import lxml -import lxml.etree from lxml.etree import _Attrib, _Element from mscxyz import utils @@ -169,7 +167,7 @@ def __create_nested_element(self, tag: str) -> _Element: for tag in tags: element: _Element | None = parent.find(tag) if element is None: - parent = lxml.etree.SubElement(parent, tag) + _, parent = self.xml.create_sub_element(parent, tag) else: parent = element return parent @@ -336,10 +334,10 @@ def __get_text_style_element(self, name: str) -> _Element: raise ValueError(f"Parent not found on element {el}!") return el else: - el_text_style: _Element = lxml.etree.SubElement( + _, el_text_style = self.xml.create_sub_element( self.parent_element, "TextStyle" ) - el_name: _Element = lxml.etree.SubElement(el_text_style, "name") + _, el_name = self.xml.create_sub_element(el_text_style, "name") el_name.text = name return el_text_style @@ -395,7 +393,7 @@ def set_text_style(self, name: str, values: dict[str, str | int | float]) -> Non for element_name, value in values.items(): element: _Element | None = text_style.find(element_name) if element is None: - element = lxml.etree.SubElement(text_style, element_name) + _, element = self.xml.create_sub_element(text_style, element_name) element.text = str(value) def get_all_fonts(self) -> list[tuple[str, str]]: @@ -562,7 +560,7 @@ def load_styles_as_string(self, styles: str) -> None: if "' - style = lxml.etree.XML(styles) + style = self.xml.parse_string(styles) self.__set_parent_style_element(style[0]) def load_style_file(self, file: str | Path | TextIOWrapper) -> None: