+def prettify(elem, indent = 0):
+ s = "\n" + indent * " "
+ if len(elem):
+ if not elem.text or not elem.text.strip():
+ elem.text = s + " "
+ for e in elem:
+ prettify(e, indent + 1)
+ if not e.tail or not e.tail.strip():
+ e.tail = s + " "
+ if not e.tail or not e.tail.strip():
+ e.tail = s
+ else:
+ if indent and (not elem.tail or not elem.tail.strip()):
+ elem.tail = s
+