Skip to content

Commit

Permalink
[3.9] bpo-29566: binhex.binhex now consitently writes MacOS 9 line en…
Browse files Browse the repository at this point in the history
…dings. (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 <ronaldoussoren@mac.com>

Automerge-Triggered-By: GH:ronaldoussoren
  • Loading branch information
miss-islington committed Nov 1, 2020
1 parent cfcb952 commit 3defcba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/binhex.py
Expand Up @@ -117,12 +117,12 @@ def _flush(self, force):
first = 0
while first <= len(self.hqxdata) - self.linelen:
last = first + self.linelen
self.ofp.write(self.hqxdata[first:last] + b'\n')
self.ofp.write(self.hqxdata[first:last] + b'\r')
self.linelen = LINELEN
first = last
self.hqxdata = self.hqxdata[first:]
if force:
self.ofp.write(self.hqxdata + b':\n')
self.ofp.write(self.hqxdata + b':\r')

def close(self):
if self.data:
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_binhex.py
Expand Up @@ -48,6 +48,18 @@ def test_binhex_error_on_long_filename(self):

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

def test_binhex_line_endings(self):
# bpo-29566: Ensure the line endings are those for macOS 9
with open(self.fname1, 'wb') as f:
f.write(self.DATA)

binhex.binhex(self.fname1, self.fname2)

with open(self.fname2, 'rb') as fp:
contents = fp.read()

self.assertNotIn(b'\n', contents)

def test_main():
support.run_unittest(BinHexTestCase)

Expand Down
@@ -0,0 +1 @@
``binhex.binhex()`` consisently writes macOS 9 line endings.

0 comments on commit 3defcba

Please sign in to comment.