Skip to content

Commit 5360f1c

Browse files
author
Steve Canny
committed
model: add PkgItem.prettify_xml()
1 parent abc7611 commit 5360f1c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

opcdiag/model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ def prettify_xml(self):
188188
Reformat the XML in this package item to indented, human-readable
189189
form. Does nothing if this package item does not contain XML.
190190
"""
191-
raise NotImplementedError
191+
if self.is_content_types or self.is_xml_part or self.is_rels_item:
192+
self._blob = etree.tostring(
193+
self.element, encoding='UTF-8', standalone=True,
194+
pretty_print=True
195+
)
192196

193197
@property
194198
def uri(self):

tests/test_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,14 @@ def it_can_calculate_its_effective_path(self):
236236
expected_path = ('root_uri\\uri' if sys.platform.startswith('win')
237237
else 'root_uri/uri')
238238
assert pkg_item.path == expected_path
239+
240+
def it_can_prettify_its_xml(self):
241+
blob = '<foo><bar/></foo>'
242+
pkg_item = PkgItem(None, 'foo.xml', blob)
243+
pkg_item.prettify_xml()
244+
assert pkg_item.blob == (
245+
'<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n'
246+
'<foo>\n'
247+
' <bar/>\n'
248+
'</foo>\n'
249+
)

0 commit comments

Comments
 (0)