Message117864
| Author |
amaury.forgeotdarc |
| Recipients |
BreamoreBoy, Richard.Urwin, amaury.forgeotdarc, bugok, effbot, flox, nnorwitz, rurwin |
| Date |
2010年10月02日.09:56:27 |
| SpamBayes Score |
0.000419802 |
| Marked as misclassified |
No |
| Message-id |
<1286013391.41.0.658493601343.issue1767933@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Python 3.1 improves the situation, the file looks more like utf-16, except that the BOM ("\xff\xfe") is repeated all the time, probably on every internal call to file.write().
Here is a test script that should work on both 2.7 and 3.1.
from io import BytesIO
from xml.etree.ElementTree import ElementTree
content = "<?xml version='1.0' encoding='UTF-16'?><html></html>"
input = BytesIO(content.encode('utf-16'))
tree = ElementTree()
tree.parse(input)
# Write content
output = BytesIO()
tree.write(output, encoding="utf-16")
assert output.getvalue().decode('utf-16') == content |
|