code: def etree_write(tree, stream):
      
      try:
          tree.write(stream, encoding="utf-8", xml_declaration=True)
      except TypeError:
          tree.write(stream, encoding="unicode", xml_declaration=True)
docs: Write XML ElementTree 'root' content into 'stream'.
  
      :param tree: XML ElementTree object
      :param stream: File or file-like object can write to