def _pretty_xml(element, level=0):
 i = ('\n' + (level * '  '))
 if len(element):
  if ((not element.text) or (not element.text.strip())):
   element.text = (i + '  ')
  if ((not element.tail) or (not element.tail.strip())):
   element.tail = i
  for sub_element in element:
   _pretty_xml(sub_element, (level + 1))
  if ((not sub_element.tail) or (not sub_element.tail.strip())):
   sub_element.tail = i
 elif (level and ((not element.tail) or (not element.tail.strip()))):
  element.tail = i
 if (not level):
  return ('<?xml version="1.0"?>\n%s' % ET.tostring(element, 'unicode'))

def _pretty_xml ( element , level = 0 ) : i = ( '\n' + ( level * '  ' ) ) if len ( element ) : if ( ( not element . text ) or ( not element . text . strip ( ) ) ) : element . text = ( i + '  ' ) if ( ( not element . tail ) or ( not element . tail . strip ( ) ) ) : element . tail = i for sub_element in element : _pretty_xml ( sub_element , ( level + 1 ) ) if ( ( not sub_element . tail ) or ( not sub_element . tail . strip ( ) ) ) : sub_element . tail = i elif ( level and ( ( not element . tail ) or ( not element . tail . strip ( ) ) ) ) : element . tail = i if ( not level ) : return ( '<?xml version="1.0"?>\n%s' % ET . tostring ( element , 'unicode' ) )
indent an elementtree element and its children .