From 51e21d0e081f2e62e99187dd22538dcb750cafa4 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Mon, 11 Dec 2023 23:21:42 +0000 Subject: [PATCH 1/2] reenable nsmap for root element Makes it possible (again) to avoid the `kml:` prefix on every single tag in the XML output. Fixes: 84103d97bf18 ("fix visibility and tests") Fixes: 768a44c7a7a8 ("Refactor XML subelement handling in KML class") --- fastkml/kml.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastkml/kml.py b/fastkml/kml.py index 5a110130..a2181511 100644 --- a/fastkml/kml.py +++ b/fastkml/kml.py @@ -85,11 +85,12 @@ def etree_element( root = config.etree.Element(f"{self.ns}kml") # type: ignore[attr-defined] root.set("xmlns", config.KMLNS[1:-1]) else: - try: + if hasattr(config.etree, "LXML_VERSION"): root = config.etree.Element( # type: ignore[attr-defined] f"{self.ns}kml", + nsmap={None: self.ns[1:-1]}, ) - except TypeError: + else: root = config.etree.Element( # type: ignore[attr-defined] f"{self.ns}kml", ) From 38706a6e4a11fe1ef7d9b3ae58e361c97841cd5e Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sun, 7 Jan 2024 17:41:44 +0000 Subject: [PATCH 2/2] 'Refactored by Sourcery' --- fastkml/kml.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fastkml/kml.py b/fastkml/kml.py index 5fb47abb..cf43c804 100644 --- a/fastkml/kml.py +++ b/fastkml/kml.py @@ -84,16 +84,15 @@ def etree_element( if not self.ns: root = config.etree.Element(f"{self.ns}kml") # type: ignore[attr-defined] root.set("xmlns", config.KMLNS[1:-1]) + elif hasattr(config.etree, "LXML_VERSION"): + root = config.etree.Element( # type: ignore[attr-defined] + f"{self.ns}kml", + nsmap={None: self.ns[1:-1]}, + ) else: - if hasattr(config.etree, "LXML_VERSION"): - root = config.etree.Element( # type: ignore[attr-defined] - f"{self.ns}kml", - nsmap={None: self.ns[1:-1]}, - ) - else: - root = config.etree.Element( # type: ignore[attr-defined] - f"{self.ns}kml", - ) + root = config.etree.Element( # type: ignore[attr-defined] + f"{self.ns}kml", + ) xml_subelement_list( obj=self, element=root,