]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix StringIO newline translation #5456
authorBenjamin Peterson <benjamin@python.org>
Mon, 9 Mar 2009 21:16:41 +0000 (21:16 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 9 Mar 2009 21:16:41 +0000 (21:16 +0000)
Lib/io.py
Lib/test/test_memoryio.py

index c2c1067a2d03c7bf92eea47bf7a8ca4f21ec3b9e..9a34d1664779ddb263f66d5df6dd587850ef91cf 100644 (file)
--- 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
 
index d1745bcd3fdf31ede503df7a601cec191e70947e..1aad3a50d13b61d63b5352bafd3dcf2619752220 100644 (file)
@@ -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()