From 9fa094677186b4bb05e488e5bc9d5dfe7ec32812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Mon, 10 Jan 2005 12:01:39 +0000 Subject: [PATCH] Fix and test for SF bug #1098990: codec readline() splits lines apart. --- Lib/codecs.py | 4 ++-- Lib/test/test_codecs.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Lib/codecs.py b/Lib/codecs.py index f6d480cc982..b283925e01f 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -322,9 +322,9 @@ class StreamReader(Codec): line = line0withend else: line = line0withoutend - break + break # we didn't get anything or this was our only try - elif not data or size is not None: + if not data or size is not None: if line and not keepends: line = line.splitlines(False)[0] break diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 99ed82d63b3..dbe9b88dbd8 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -108,6 +108,36 @@ class ReadTest(unittest.TestCase): writer.write(u"foo\r\n") self.assertEqual(reader.readline(keepends=True), u"foo\r\n") + def test_bug1098990_a(self): + s1 = u"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\r\n" + s2 = u"offending line: ladfj askldfj klasdj fskla dfzaskdj fasklfj laskd fjasklfzzzzaa%whereisthis!!!\r\n" + s3 = u"next line.\r\n" + + s = (s1+s2+s3).encode(self.encoding) + stream = StringIO.StringIO(s) + reader = codecs.getreader(self.encoding)(stream) + self.assertEqual(reader.readline(), s1) + self.assertEqual(reader.readline(), s2) + self.assertEqual(reader.readline(), s3) + self.assertEqual(reader.readline(), u"") + + def test_bug1098990_b(self): + s1 = u"aaaaaaaaaaaaaaaaaaaaaaaa\r\n" + s2 = u"bbbbbbbbbbbbbbbbbbbbbbbb\r\n" + s3 = u"stillokay:bbbbxx\r\n" + s4 = u"broken!!!!badbad\r\n" + s5 = u"againokay.\r\n" + + s = (s1+s2+s3+s4+s5).encode(self.encoding) + stream = StringIO.StringIO(s) + reader = codecs.getreader(self.encoding)(stream) + self.assertEqual(reader.readline(), s1) + self.assertEqual(reader.readline(), s2) + self.assertEqual(reader.readline(), s3) + self.assertEqual(reader.readline(), s4) + self.assertEqual(reader.readline(), s5) + self.assertEqual(reader.readline(), u"") + class UTF16Test(ReadTest): encoding = "utf-16"