diff options
| author | Ronald Oussoren <ronaldoussoren@mac.com> | 2020-11-01 09:08:48 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-01 09:08:48 (GMT) |
| commit | 2165cea548f961b308050f30d1f042a377651d44 (patch) | |
| tree | 77d97dfecbba2440090fe4628724bf85bebc855d | |
| parent | d3b4e068077dd26927ae7485bd0303e09d962c02 (diff) | |
| download | cpython-2165cea548f961b308050f30d1f042a377651d44.zip cpython-2165cea548f961b308050f30d1f042a377651d44.tar.gz cpython-2165cea548f961b308050f30d1f042a377651d44.tar.bz2 | |
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.
| -rw-r--r-- | Lib/binhex.py | 4 | ||||
| -rw-r--r-- | Lib/test/test_binhex.py | 12 | ||||
| -rw-r--r-- | Misc/NEWS.d/next/Library/2020-10-31-13-28-36.bpo-29566.6aDbty.rst | 1 |
3 files changed, 15 insertions, 2 deletions
diff --git a/Lib/binhex.py b/Lib/binhex.py index 9559f46..ace5217 100644 --- a/Lib/binhex.py +++ b/Lib/binhex.py @@ -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: diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py index 5e59f57..efc1654 100644 --- a/Lib/test/test_binhex.py +++ b/Lib/test/test_binhex.py @@ -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 index 0000000..d54c714 --- /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. |
