From 412a189cdefd0f2e363fe3cc2d8806876ac74854 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 9 Mar 2009 21:16:41 +0000 Subject: [PATCH] fix StringIO newline translation #5456 --- Lib/io.py | 3 +-- Lib/test/test_memoryio.py | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/io.py b/Lib/io.py index c2c1067a2d03..9a34d1664779 100644 --- a/Lib/io.py +++ b/Lib/io.py @@ -1942,13 +1942,12 @@ try: self._seennl |= (lf and self._LF) | (cr and self._CR) \ | (crlf and self._CRLF) + output = input if self._readtranslate: if crlf: output = input.replace("\r\n", "\n") if cr: output = input.replace("\r", "\n") - else: - output = input return output diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index d1745bcd3fdf..1aad3a50d13b 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -376,6 +376,10 @@ class PyStringIOTest(MemoryTestMixin, unittest.TestCase): ioclass = io._StringIO EOF = "" + def test_newline_none(self): + memio = self.ioclass('hello\r\nhi\r\n', newline=None) + self.assertEqual(memio.readlines(), ["hello\n", "hi\n"]) + def test_relative_seek(self): memio = self.ioclass() -- 2.47.3