def write_element_tempfile(element, tempfile): """ Writes element to temp file """ if element != None and ElementTree.iselement(element): try: tempfile.write(ElementTree.tostring(element)) except Exception, e: raise exceptions.ConeException( 'Cannot write Element to file (%s). Exception: %s' % (tempfile, e))
def write_element(element, output, linesep=os.linesep): """ """ if element != None and ElementTree.iselement(element): enc = None try: out_file = open(output, 'w') out_string = ElementTree.tostring(element) out_string = out_string.replace('\r\n', linesep) out_string = out_string.replace('\n', linesep) out_file.write(out_string) out_file.close() except Exception, e: raise exceptions.ConeException( 'Cannot write Element to file (%s). Exception: %s' % (output, e))
def write_element_enc(element, output, enc, linesep=os.linesep): """ Writes element to file """ if element != None and ElementTree.iselement(element): enc = None try: remove_namespace(element, 'http://www.s60.com/xml/genconfml/1') out_file = codecs.open(output, 'w', enc) output_string = ElementTree.tostring(element) output_string = output_string.replace('\r\n', linesep) output_string = output_string.replace('\n', linesep) out_file.write(output_string) out_file.close() except Exception, e: raise exceptions.ConeException( 'Cannot write Element to file (%s). Exception: %s' % (output, e))