Skip to content

Commit 3defcba

Browse files
[3.9] bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059) (GH-23071)
[[bpo-29566]()]() notes that binhex.binhex uses inconsistent line endings (both Unix and MacOS9 line endings are used). This PR changes this to use the MacOS9 line endings everywhere. (cherry picked from commit 2165cea) Co-authored-by: Ronald Oussoren <[email protected]> Automerge-Triggered-By: GH:ronaldoussoren
1 parent cfcb952 commit 3defcba

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Lib/binhex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ def _flush(self, force):
117117
first = 0
118118
while first <= len(self.hqxdata) - self.linelen:
119119
last = first + self.linelen
120-
self.ofp.write(self.hqxdata[first:last] + b'\n')
120+
self.ofp.write(self.hqxdata[first:last] + b'\r')
121121
self.linelen = LINELEN
122122
first = last
123123
self.hqxdata = self.hqxdata[first:]
124124
if force:
125-
self.ofp.write(self.hqxdata + b':\n')
125+
self.ofp.write(self.hqxdata + b':\r')
126126

127127
def close(self):
128128
if self.data:

Lib/test/test_binhex.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ def test_binhex_error_on_long_filename(self):
4848

4949
self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
5050

51+
def test_binhex_line_endings(self):
52+
# bpo-29566: Ensure the line endings are those for macOS 9
53+
with open(self.fname1, 'wb') as f:
54+
f.write(self.DATA)
55+
56+
binhex.binhex(self.fname1, self.fname2)
57+
58+
with open(self.fname2, 'rb') as fp:
59+
contents = fp.read()
60+
61+
self.assertNotIn(b'\n', contents)
62+
5163
def test_main():
5264
support.run_unittest(BinHexTestCase)
5365

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``binhex.binhex()`` consisently writes macOS 9 line endings.

0 commit comments

Comments
 (0)