Mercurial > hg > lxmldump
changeset 12:d50e71642be7
Moar.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 May 2021 11:46:42 +0300 |
parents | b2ac68732e45 |
children | 3bd772fd6a50 |
files | lxmldump.py |
diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/lxmldump.py Tue May 11 11:30:42 2021 +0300 +++ b/lxmldump.py Tue May 11 11:46:42 2021 +0300 @@ -56,10 +56,15 @@ ## Wrapper for print() def pkk_print(smsg): - if pkk_cfg["normalize"]: - sys.stdout.write(unicodedata.normalize("NFC", smsg)) - else: - sys.stdout.write(smsg) + try: + if pkk_cfg["normalize"]: + sys.stdout.write(unicodedata.normalize("NFC", smsg)) + else: + sys.stdout.write(smsg) + + except (BrokenPipeError, IOError) as e: + sys.stderr.close() + def pkk_printi(indent, smsg): pkk_print((" " * indent) + smsg) @@ -88,7 +93,6 @@ def pkk_ptr_to_text(pnode): -# return "PTR: {}".format(xmlET.tostring(pnode)) return "PTR: <{}>{}</>".format( pnode.attrib["{http://www.w3.org/TR/xlink}href"], ("".join(pnode.itertext())).strip()) @@ -141,6 +145,7 @@ for qnode in dnode.findall(dsub): pkk_printi(indent, dfmt.format(pkk_get_text(qnode))) + def pkk_output_subs(indent, dnode, dsub, dname): for qnode in dnode.findall(dsub): pkk_printi(indent, "{} \"{}\"\n".format(dname, pkk_get_text(qnode)))