]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059)
authorRonald Oussoren <ronaldoussoren@mac.com>
Sun, 1 Nov 2020 09:08:48 +0000 (10:08 +0100)
committerGitHub <noreply@github.com>
Sun, 1 Nov 2020 09:08:48 +0000 (01:08 -0800)
[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.

Lib/binhex.py
Lib/test/test_binhex.py
Misc/NEWS.d/next/Library/2020-10-31-13-28-36.bpo-29566.6aDbty.rst [new file with mode: 0644]

index 9559f46d5a288215f9ebfd5a114174f8326ed2bf..ace5217d2713921d2b03c1a956a0f23ed0bdbccb 100644 (file)
@@ -117,12 +117,12 @@ class _Hqxcoderengine:
         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:
index 5e59f5761514c61e839833ec7935806b30cc7311..efc1654a6b7107a2e6cf2b90cc97b9c4df3ab629 100644 (file)
@@ -52,6 +52,18 @@ class BinHexTestCase(unittest.TestCase):
 
         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 (file)
index 0000000..d54c714
--- /dev/null
@@ -0,0 +1 @@
+``binhex.binhex()`` consisently writes macOS 9 line endings.