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: binhex() creates files with mixed line endings
Type: behavior Stage: resolved
Components: macOS Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, ned.deily, ronaldoussoren, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-02-15 12:21 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23059 merged ronaldoussoren, 2020-10-31 12:32
PR 23070 merged miss-islington, 2020-11-01 09:09
PR 23071 merged miss-islington, 2020-11-01 09:11
Messages (5)
msg287849 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-15 12:21
binhex.binhex() creates files with mixed line endings in Python 3. The header line '(This file must be converted with BinHex 4.0)' is separated from the data by LFs, but the data is split for lines by CRs.

>>> import binhex
>>> with open('inp', 'wb') as f: f.write(bytes(range(256)))
... 
256
>>> binhex.binhex('inp', 'outp')
>>> for line in open('outp', 'rb').read().splitlines(True): print(repr(line))
... 
b'(This file must be converted with BinHex 4.0)\r'
b'\r'
b':!fPZF!!rN!J!N!3"!*!&*VF!!3)$"!8\'"`J*#JX-$3i2%"%5%a39&KFB\'4SE("d\n'
b'H(b!K)L-N*5BR+#NU+b`Y,Lm`-6)c0$8f0cJj1MXm26ir3%&#3d4&4NG)58T,6%e\n'
b'16e"48P0899CA@&PD@eaGAPpJB@*MC\'9QCfKTDQYXE@j[F(&bFh4eGRGiHATlI(e\n'
b'qIi#"JS1%KBD(L)Q+Lib0MSq3!*\'5Nj59PTHBQCUER*fHRk#KSU1NTDDRU+QUUkb\n'
b'YVUq`XE+cY,@fYlLjZVZm[Ekr`-(#`m6&aXI)bFV,c-h1cp$4dY28eGEAf0RDfpc\n'
b'GhYrJiH,Mj1AQjqMTkZ[XlHl[m2(bmr6ep[IiqIVlr2hqrhj9!!!:\n'

In Python 2 the output file was file object usually opened in text mode. Newline characters were translated to platform-depending line endings: CRLF on Windows, LF on classic Mac OS. In Python 2 the output file is binary stream that doesn't do any newline translations.

The last related commit is 34a042d301d6ab88645046a6dfa6c38265ca4b39 with Guido's message "This is the last time I fix binhex.  If it breaks again it goes in the dustbin."
msg380056 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-10-31 12:34
I've added a PR that changes the line ending to "\r" in encoded data.

Not very useful now that binhex is deprecated, but this allows us to close this issue.
msg380121 - (view) Author: miss-islington (miss-islington) Date: 2020-11-01 09:08
New changeset 2165cea548f961b308050f30d1f042a377651d44 by Ronald Oussoren in branch 'master':
bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059)
https://github.com/python/cpython/commit/2165cea548f961b308050f30d1f042a377651d44
msg380123 - (view) Author: miss-islington (miss-islington) Date: 2020-11-01 09:39
New changeset 39a56e55231be00d52fa183fcd2b7d88619ced4b by Miss Skeleton (bot) in branch '3.8':
[3.8] bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059) (GH-23070)
https://github.com/python/cpython/commit/39a56e55231be00d52fa183fcd2b7d88619ced4b
msg380124 - (view) Author: miss-islington (miss-islington) Date: 2020-11-01 09:39
New changeset 3defcbac2c9ff4306ed5b7fb37d12637eb188306 by Miss Skeleton (bot) in branch '3.9':
[3.9] bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059) (GH-23071)
https://github.com/python/cpython/commit/3defcbac2c9ff4306ed5b7fb37d12637eb188306
History
Date User Action Args
2022-04-11 14:58:43adminsetgithub: 73752
2020-11-01 09:39:48miss-islingtonsetmessages: + msg380124
2020-11-01 09:39:47miss-islingtonsetmessages: + msg380123
2020-11-01 09:38:54serhiy.storchakasetresolution: duplicate -> fixed
2020-11-01 09:11:17miss-islingtonsetpull_requests: + pull_request21991
2020-11-01 09:10:25ronaldoussorensetstatus: open -> closed
resolution: duplicate
stage: patch review -> resolved
2020-11-01 09:09:08miss-islingtonsetpull_requests: + pull_request21990
2020-11-01 09:08:51miss-islingtonsetnosy: + miss-islington
messages: + msg380121
2020-10-31 12:34:04ronaldoussorensetmessages: + msg380056
versions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.5, Python 3.6, Python 3.7
2020-10-31 12:32:07ronaldoussorensetkeywords: + patch
stage: patch review
pull_requests: + pull_request21978
2017-02-15 23:48:36gvanrossumsetnosy: - gvanrossum
2017-02-15 12:21:05serhiy.storchakacreate