From b165be1248de61c6aa93d5d5889bbcfed5bccdb0 Mon Sep 17 00:00:00 2001 From: Manfred Stock Date: Mon, 15 Nov 2021 22:20:37 +0100 Subject: [PATCH] Stringify SVG as ASCII with entity encoding It seems that when processing a SVG file passed via a pipe, Inkscape emits errors/warnings about an XML parser error if the SVG file is UTF-8 encoded. It still does seem to successfully process the SVG file and generates the expected output, however, these messages are at least confusing. Not passing the encoding parameter to etree.tostring() makes it output ASCII with non-ASCII characters encoded as XML entities, so this can then be correctly parsed again, and this does not seem to 'confuse' Inkscape. --- svgtemplate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgtemplate.py b/svgtemplate.py index 410934c..57fea9d 100644 --- a/svgtemplate.py +++ b/svgtemplate.py @@ -42,7 +42,7 @@ def transform(self, frame): # if '$subtitle' in task.parameters and task.parameters['$subtitle'] == '': # child = svg.findall(".//*[@id='subtitle']")[0] # child.getparent().remove(child) - self.svgstr = etree.tostring(svg, encoding='unicode') + self.svgstr = etree.tostring(svg).decode('UTF-8') def __exit__(self, exception_type, exception_value, traceback): pass