summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-12-13 17:29:16 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-12-13 17:29:16 (GMT)
commit414721614f6f550f8d8353b09b178e1d055f1d1f (patch)
treea5f69d893fc93c290aa5e7801abe5f518b27774a /Lib
parent4895af4ef1c91679e642c0fc81f584aecc26a7ea (diff)
downloadcpython-414721614f6f550f8d8353b09b178e1d055f1d1f.zip
cpython-414721614f6f550f8d8353b09b178e1d055f1d1f.tar.gz
cpython-414721614f6f550f8d8353b09b178e1d055f1d1f.tar.bz2
make StringIO like other file objects in that readline(-1) has no effect #7348
Diffstat (limited to 'Lib')
-rw-r--r--Lib/StringIO.py2
-rw-r--r--Lib/test/test_StringIO.py2
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()