def elementtree_indent(elem, level=0):
 i = ('\n' + (level * '  '))
 if len(elem):
  if ((not elem.text) or (not elem.text.strip())):
   elem.text = (i + '  ')
  for elem in elem:
   elementtree_indent(elem, (level + 1))
  if ((not elem.tail) or (not elem.tail.strip())):
   elem.tail = i
 elif (level and ((not elem.tail) or (not elem.tail.strip()))):
  elem.tail = i

def elementtree_indent ( elem , level = 0 ) : i = ( '\n' + ( level * '  ' ) ) if len ( elem ) : if ( ( not elem . text ) or ( not elem . text . strip ( ) ) ) : elem . text = ( i + '  ' ) for elem in elem : elementtree_indent ( elem , ( level + 1 ) ) if ( ( not elem . tail ) or ( not elem . tail . strip ( ) ) ) : elem . tail = i elif ( level and ( ( not elem . tail ) or ( not elem . tail . strip ( ) ) ) ) : elem . tail = i
recursive function to indent an elementtree .