Skip to content

Commit 2165cea

Browse files
bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059)
[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.
1 parent d3b4e06 commit 2165cea

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
@@ -52,6 +52,18 @@ def test_binhex_error_on_long_filename(self):
5252

5353
self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
5454

55+
def test_binhex_line_endings(self):
56+
# bpo-29566: Ensure the line endings are those for macOS 9
57+
with open(self.fname1, 'wb') as f:
58+
f.write(self.DATA)
59+
60+
binhex.binhex(self.fname1, self.fname2)
61+
62+
with open(self.fname2, 'rb') as fp:
63+
contents = fp.read()
64+
65+
self.assertNotIn(b'\n', contents)
66+
5567
def test_main():
5668
support.run_unittest(BinHexTestCase)
5769

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)