Message97386
open_bom.patch is the proof of concept. It only works in read mode. The idea is to delay the creation of the encoding and the decoder. We wait for just after the first read_chunk().
The patch changes the default behaviour of open(): if the file starts with a BOM, the BOM is used but skipped. Example:
-------------
from _pyio import open
with open('test.txt', 'w', encoding='utf-8-sig') as fp:
print("abc", file=fp)
print("d\xe9f", file=fp)
with open('test.txt', 'r') as fp:
print("open().read(): {!r}".format(fp.read()))
-------------
Unpatched Python displays '\ufeffabc\ndéf\n', whereas patched Python displays 'abc\ndéf\n'. |
|
Date |
User |
Action |
Args |
2010-01-07 23:18:52 | vstinner | set | recipients:
+ vstinner, pitrou |
2010-01-07 23:18:50 | vstinner | set | messageid: <1262906330.66.0.125497764461.issue7651@psf.upfronthosting.co.za> |
2010-01-07 23:18:49 | vstinner | link | issue7651 messages |
2010-01-07 23:18:48 | vstinner | create | |
|