[issue22982] BOM incorrectly inserted before writing, after seeking in text file
Roundup Robot added the comment: New changeset 946740824eaf by Antoine Pitrou in branch '3.4': Issue #22982: Improve BOM handling when seeking to multiple positions of a writable text file. https://hg.python.org/cpython/rev/946740824eaf New changeset 3583e5191b96 by Antoine Pitrou in branch 'default': Issue #22982: Improve BOM handling when seeking to multiple positions of a writable text file. https://hg.python.org/cpython/rev/3583e5191b96 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22982 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22982] BOM incorrectly inserted before writing, after seeking in text file
Antoine Pitrou added the comment: Fix is pushed. Thanks for the report! -- resolution: - fixed stage: patch review - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22982 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22982] BOM incorrectly inserted before writing, after seeking in text file
Antoine Pitrou added the comment: Here is a patch. -- keywords: +patch stage: - patch review versions: +Python 3.5 Added file: http://bugs.python.org/file37378/bom_seek_append.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22982 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22982] BOM incorrectly inserted before writing, after seeking in text file
Antoine Pitrou added the comment: This is a limitation more than a bug. When you seek to the start of the file, the encoder is reset because Python thinks you are gonna to write there. If you remove the call to `file.seek(0, io.SEEK_SET)`, things work fine. @Amaury, whence can only be zero there: https://hg.python.org/cpython/file/0744ceb5c0ed/Lib/_pyio.py#l1960 -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22982 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22982] BOM incorrectly inserted before writing, after seeking in text file
Mark Ingram added the comment: It's more than a limitation, because if I call `file.seek(0, io.SEEK_END)` then the encoder is still reset, and will still write the BOM, even at the end of the file. This also means that it's impossible to seek in a text file that you want to append to. I've had to work around this by opening the file as binary, manually writing the BOM, and writing the strings as encoded bytes. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22982 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22982] BOM incorrectly inserted before writing, after seeking in text file
New submission from MarkIngramUK: If you open a text file for append, but then perform any form of seeking, before attempting to write to the file, it will cause the BOM to be written before you text. See the attached file for an example. If you run the test, take a look at the output file, and you'll notice the UTF16 BOM gets written out before each number. I'm running a 2014 iMac with Yosemite. -- components: IO files: append-test.py messages: 232015 nosy: MarkIngramUK priority: normal severity: normal status: open title: BOM incorrectly inserted before writing, after seeking in text file type: behavior versions: Python 3.4 Added file: http://bugs.python.org/file37345/append-test.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22982 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22982] BOM incorrectly inserted before writing, after seeking in text file
Amaury Forgeot d'Arc added the comment: issue5006 was supposed to take care of this, but it has a flaw IMO: This statement https://hg.python.org/cpython/file/0744ceb5c0ed/Lib/_pyio.py#l2003 is missing an and whence!=2. -- nosy: +amaury.forgeotdarc ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22982 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com