def getXML(obj, ttFont): """Call the object's toXML() method and return the writer's content as string. Result is stripped of XML declaration and OS-specific newline characters. """ writer = XMLWriter(BytesIO()) # don't write OS-specific new lines writer.newlinestr = writer.totype('') # erase XML declaration writer.file.seek(0) writer.file.truncate() obj.toXML(writer, ttFont) xml = writer.file.getvalue().decode("utf-8") return xml
def getXML(func, ttFont=None): """Call the passed toXML function and return the written content as string. Result is stripped of XML declaration and OS-specific newline characters. """ writer = XMLWriter(BytesIO()) # don't write OS-specific new lines writer.newlinestr = writer.totype('') # erase XML declaration writer.file.seek(0) writer.file.truncate() func(writer, ttFont) xml = writer.file.getvalue().decode("utf-8") return xml