Skip to content

Commit 414ab69

Browse files
committed
Fix array indentation of pretty xml
Fix indentation on closing element of arrays.
1 parent c806ece commit 414ab69

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llsd/serde_xml.py

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def _ARRAY(self, v):
119119
self._indent()
120120
self._generate(item)
121121
self._depth -= 1
122+
self._indent()
122123
self.stream.writelines([b'</array>', self._eol])
123124
def _MAP(self, v):
124125
self.stream.writelines([b'<map>', self._eol])

tests/llsd_test.py

+20
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,24 @@ def testFormatPrettyXML(self):
15031503

15041504
output_xml = llsd.format_pretty_xml(python_object)
15051505

1506+
with open("foo.llsd.xml", "wb") as f:
1507+
f.write(output_xml)
1508+
1509+
self.assertEqual(output_xml.decode("utf8"), """<?xml version="1.0" ?>
1510+
<llsd>
1511+
<map>
1512+
<key>id</key>
1513+
<array>
1514+
<string>string1</string>
1515+
<integer>123</integer>
1516+
<map>
1517+
<key>name</key>
1518+
<integer>123</integer>
1519+
</map>
1520+
</array>
1521+
</map>
1522+
</llsd>""")
1523+
15061524
# check whether the output_xml contains whitespaces and new line character
15071525
whitespaces_count = output_xml.count(b' ')
15081526
newline_count = output_xml.count(b'\n')
@@ -1944,3 +1962,5 @@ def test_uuid_map_key(self):
19441962
llsdmap=llsd.LLSD({uuid.UUID(int=0) : 'uuid'})
19451963
self.assertEqual(llsd.format_xml(llsdmap), b'<?xml version="1.0" ?><llsd><map><key>00000000-0000-0000-0000-000000000000</key><string>uuid</string></map></llsd>')
19461964
self.assertEqual(llsd.format_notation(llsdmap), b"{'00000000-0000-0000-0000-000000000000':'uuid'}")
1965+
1966+

0 commit comments

Comments
 (0)