Skip to content

Commit

Permalink
Python 3.13 introduced new attr argument to _write_data (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke authored Jan 8, 2025
1 parent 5b58354 commit 626fc4b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/xacro/xmlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ def reqd_attrs(tag, attrs):
raise RuntimeError("%s: missing attribute '%s'" % (tag.nodeName, name))
return result

# Python 3.13 introduced a new argument to xml.dom.minidom._write_data
# https://github.com/ros/xacro/issues/352
_WRITE_DATA_EXTRA_KWARGS = dict(attr=True)
try:
xml.dom.minidom._write_data(None, None, attr=True)
except TypeError:
_WRITE_DATA_EXTRA_KWARGS = {}

# Better pretty printing of xml
# Taken from http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/
Expand All @@ -120,7 +127,7 @@ def fixed_writexml(self, writer, indent="", addindent="", newl=""):

for a_name in a_names:
writer.write(" %s=\"" % a_name)
xml.dom.minidom._write_data(writer, attrs[a_name].value)
xml.dom.minidom._write_data(writer, attrs[a_name].value, **_WRITE_DATA_EXTRA_KWARGS)
writer.write("\"")
if self.childNodes:
if len(self.childNodes) == 1 \
Expand Down

0 comments on commit 626fc4b

Please sign in to comment.