[Python-checkins] [3.8] bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059) (GH-23070)

miss-islington webhook-mailer at python.org
Sun Nov 1 04:39:48 EST 2020


https://github.com/python/cpython/commit/39a56e55231be00d52fa183fcd2b7d88619ced4b
commit: 39a56e55231be00d52fa183fcd2b7d88619ced4b
branch: 3.8
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-11-01T01:39:16-08:00
summary:

[3.8] bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059) (GH-23070)



[[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 2165cea548f961b308050f30d1f042a377651d44)


Co-authored-by: Ronald Oussoren <ronaldoussoren at mac.com>

Automerge-Triggered-By: GH:ronaldoussoren

files:
A Misc/NEWS.d/next/Library/2020-10-31-13-28-36.bpo-29566.6aDbty.rst
M Lib/binhex.py
M Lib/test/test_binhex.py

diff --git a/Lib/binhex.py b/Lib/binhex.py
index 56b5f852c0038..a4d8789fd6d09 100644
--- a/Lib/binhex.py
+++ b/Lib/binhex.py
@@ -100,12 +100,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:
diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py
index 2f3d53afbd132..c92cfac8398f6 100644
--- a/Lib/test/test_binhex.py
+++ b/Lib/test/test_binhex.py
@@ -45,6 +45,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)
 
diff --git a/Misc/NEWS.d/next/Library/2020-10-31-13-28-36.bpo-29566.6aDbty.rst b/Misc/NEWS.d/next/Library/2020-10-31-13-28-36.bpo-29566.6aDbty.rst
new file mode 100644
index 0000000000000..d54c714688531
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-10-31-13-28-36.bpo-29566.6aDbty.rst
@@ -0,0 +1 @@
+``binhex.binhex()`` consisently writes macOS 9 line endings.



More information about the Python-checkins mailing list