This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: UTF-16 BOM is not written by socket.makefile (but is expected by read)
Type: behavior Stage:
Components: IO, Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, pitrou, serhiy.storchaka, yang
Priority: normal Keywords:

Created on 2009-10-15 20:55 by yang, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg94108 - (view) Author: Yang Zhang (yang) Date: 2009-10-15 20:55
When I call s.makefile('r',encoding='utf-16').read(), this expects a BOM, 
but s.makefile('w',encoding='utf-16').write('hello') doesn't produce it. 
This is asymmetric.

BTW is there a way to prevent the reading file from expecting a BOM?
msg94109 - (view) Author: Yang Zhang (yang) Date: 2009-10-15 20:58
To answer my own question: specify UTF-16BE or UTF-16LE
msg94250 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-10-19 18:44
The explanation is that sockets are not seekable, but the heuristic to
decide whether to write a BOM relies on tell() to return 0 on start-of-file.
If we unconditionally wrote a BOM, there would be a risk of duplicate
BOMs depending on the use case, which is more annoying than lacking a
BOM at the beginning.
msg182112 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-02-14 16:57
Won't fix?
msg182144 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-02-15 14:56
Indeed, I would suggest won't fix.
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51394
2013-02-15 14:56:13pitrousetstatus: pending -> closed
resolution: wont fix
messages: + msg182144
2013-02-14 16:57:30serhiy.storchakasetstatus: open -> pending
nosy: + serhiy.storchaka
messages: + msg182112

2009-10-19 18:44:53pitrousetpriority: normal

nosy: + pitrou
messages: + msg94250

components: + IO
2009-10-17 01:10:55ezio.melottisetnosy: + ezio.melotti
2009-10-15 20:58:39yangsetmessages: + msg94109
2009-10-15 20:55:40yangcreate