def formatify_xml(content, contentType): # todo: use the color scheme from `theme`... output = six.StringIO() pxml.prettify(six.StringIO(content.strip()), output, strict=False, color=False) return output.getvalue() or content
def test_canonicalAttributeOrder(self): src = six.BytesIO(b'<root><zig a="1" c="2" b="3">foo</zig></root>') chk = b'''\ <?xml version="1.0" encoding="UTF-8"?> <root> <zig a="1" b="3" c="2">foo</zig> </root> ''' out = six.BytesIO() self.assertTrue(pxml.prettify(src, out)) self.assertEqual(out.getvalue(), chk)
def test_encodingOverride(self): src = six.BytesIO(b'<root><zog a="b">foo</zog></root>') chk = b'''\ <?xml version="1.0" encoding="utf-8"?> <root> <zog a="b">foo</zog> </root> ''' out = six.BytesIO() self.assertTrue(pxml.prettify(src, out, encoding='utf-8')) self.assertEqual(out.getvalue(), chk)
def test_color(self): src = six.BytesIO(b'<root><zog a="b">foo</zog></root>') chk = b'''\ [32m<?xml version="1.0" encoding="UTF-8"?>(B[m [1m[35m<(B[m[1m[34mroot(B[m[1m[35m>(B[m [1m[35m<(B[m[1m[34mzog(B[m [1m[34ma(B[m[1m[35m="(B[mb[1m[35m"(B[m[1m[35m>(B[mfoo[1m[35m</(B[m[1m[34mzog(B[m[1m[35m>(B[m [1m[35m</(B[m[1m[34mroot(B[m[1m[35m>(B[m ''' out = six.BytesIO() self.assertTrue(pxml.prettify(src, out, color=True)) self.assertEqual(out.getvalue(), chk)
def test_simple(self): src = six.BytesIO(b'<root><zig><zog a="b">foo</zog><zog>bar</zog></zig></root>') chk = b'''\ <?xml version="1.0" encoding="UTF-8"?> <root> <zig> <zog a="b">foo</zog> <zog>bar</zog> </zig> </root> ''' out = six.BytesIO() self.assertTrue(pxml.prettify(src, out)) self.assertEqual(out.getvalue(), chk)
def test_simple(self): src = six.BytesIO( b'<root><zig><zog a="b">foo</zog><zog>bar</zog></zig></root>') chk = b'''\ <?xml version="1.0" encoding="UTF-8"?> <root> <zig> <zog a="b">foo</zog> <zog>bar</zog> </zig> </root> ''' out = six.BytesIO() self.assertTrue(pxml.prettify(src, out)) self.assertEqual(out.getvalue(), chk)