From ae9e8c2de6ed35870fd30960c3ae915889189c3d Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Wed, 27 Mar 2019 08:10:29 +0100 Subject: [PATCH] pretty print with lxml --- test/sync_handshake.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 31f5e81..1ca0751 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -31,6 +31,12 @@ try: except: colored = lambda x, y: x +try: + from lxml import etree + from lxml import objectify +except: + etree = None + inbox = pathlib.Path("..") / "TestInbox" device_name = "" @@ -54,9 +60,13 @@ def print_msg(p): print(colored(str(datetime.fromtimestamp(p.stat().st_mtime)), color)) m = re.search("(.*)", msg.opt_fields["pEp.sync"].replace("\n", " ")) if m: - text = m.group(1).replace("\r", "").strip() - while text.count(" "): - text = text.replace(" ", " ") + if etree: + tree = objectify.fromstring(m.group(1).replace("\r", "")) + text = etree.tostring(tree, pretty_print=True, encoding="unicode") + else: + text = m.group(1).replace("\r", "").strip() + while text.count(" "): + text = text.replace(" ", " ") print(text)