diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-12-13 17:29:16 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-12-13 17:29:16 (GMT) |
commit | 414721614f6f550f8d8353b09b178e1d055f1d1f (patch) | |
tree | a5f69d893fc93c290aa5e7801abe5f518b27774a | |
parent | 4895af4ef1c91679e642c0fc81f584aecc26a7ea (diff) | |
download | cpython-414721614f6f550f8d8353b09b178e1d055f1d1f.zip cpython-414721614f6f550f8d8353b09b178e1d055f1d1f.tar.gz cpython-414721614f6f550f8d8353b09b178e1d055f1d1f.tar.bz2 |
make StringIO like other file objects in that readline(-1) has no effect #7348
-rw-r--r-- | Lib/StringIO.py | 2 | ||||
-rw-r--r-- | Lib/test/test_StringIO.py | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 054ad4c..340fae1 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 f5a177e..d10255d 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() |