[Python-checkins] r76798 - in python/trunk/Lib: StringIO.py test/test_StringIO.py

benjamin.peterson python-checkins at python.org
Sun Dec 13 18:29:16 CET 2009


Author: benjamin.peterson
Date: Sun Dec 13 18:29:16 2009
New Revision: 76798

Log:
make StringIO like other file objects in that readline(-1) has no effect #7348

Modified:
   python/trunk/Lib/StringIO.py
   python/trunk/Lib/test/test_StringIO.py

Modified: python/trunk/Lib/StringIO.py
==============================================================================
--- python/trunk/Lib/StringIO.py	(original)
+++ python/trunk/Lib/StringIO.py	Sun Dec 13 18:29:16 2009
@@ -158,7 +158,7 @@
             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]

Modified: python/trunk/Lib/test/test_StringIO.py
==============================================================================
--- python/trunk/Lib/test/test_StringIO.py	(original)
+++ python/trunk/Lib/test/test_StringIO.py	Sun Dec 13 18:29:16 2009
@@ -28,6 +28,8 @@
         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()


More information about the Python-checkins mailing list