From 414721614f6f550f8d8353b09b178e1d055f1d1f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 13 Dec 2009 17:29:16 +0000 Subject: [PATCH] make StringIO like other file objects in that readline(-1) has no effect #7348 --- Lib/StringIO.py | 2 +- Lib/test/test_StringIO.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 054ad4c3d58..340fae12290 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -158,7 +158,7 @@ class StringIO: newpos = self.len else: newpos = i+1 - if length is not None: + if length is not None and length > 0: if self.pos + length < newpos: newpos = self.pos + length r = self.buf[self.pos:newpos] diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index f5a177ed55e..d10255de41f 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -28,6 +28,8 @@ class TestGenericStringIO(unittest.TestCase): eq(self._fp.read(10), self._line[:10]) eq(self._fp.readline(), self._line[10:] + '\n') eq(len(self._fp.readlines(60)), 2) + self._fp.seek(0) + eq(self._fp.readline(-1), self._line + '\n') def test_writes(self): f = self.MODULE.StringIO()