[elbe-devel] [PATCH 2/5] elbepack: treeutils: always handle pathlike arguments to write()
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Wed Oct 2 12:09:45 CEST 2024
Older versions of lxml don't accept os.PathLike objects for write().
Explicitly convert them to a string before.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/treeutils.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/elbepack/treeutils.py b/elbepack/treeutils.py
index 6725960d473e74d9ab4b349eedaaba2187dfcbe1..03e4e5fe80c26af8b237bf93e8cae471dc029756 100644
--- a/elbepack/treeutils.py
+++ b/elbepack/treeutils.py
@@ -3,6 +3,7 @@
# SPDX-FileCopyrightText: 2013-2017 Linutronix GmbH
import copy
+import os
from lxml.etree import Element, ElementTree, SubElement
from lxml.etree import Resolver, XMLParser, XMLSchema, fromstring, parse, tostring
@@ -146,6 +147,8 @@ class etree(ebase):
def write(self, fname, encoding=None):
# Make sure, that we end with a newline
self.et.getroot().tail = '\n'
+ if isinstance(fname, os.PathLike):
+ fname = os.fspath(fname)
self.et.write(fname, encoding=encoding)
def ensure_child(self, tag):
--
2.46.2
More information about the elbe-devel
mailing list