]> granicus.if.org Git - python/commitdiff
SF patch #1359365: file and cStringIO raise a ValueError when next() is called
authorWalter Dörwald <walter@livinglogic.de>
Wed, 15 Mar 2006 08:23:53 +0000 (08:23 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Wed, 15 Mar 2006 08:23:53 +0000 (08:23 +0000)
after calling close(). Change StringIO, so that it behaves the same way.

Lib/StringIO.py
Lib/test/test_StringIO.py

index 5c463fbc1c94cf09cd9f6e8e4166f928c32c2fa9..1e5f25408d7001cd0aabd55944b6484980d90b9e 100644 (file)
@@ -72,8 +72,7 @@ class StringIO:
         method is called repeatedly. This method returns the next input line,
         or raises StopIteration when EOF is hit.
         """
-        if self.closed:
-            raise StopIteration
+        _complain_ifclosed(self.closed)
         r = self.readline()
         if not r:
             raise StopIteration
index c61f7cc54a3c401dbcac7c224b3eb4ee86beee30..a2e544458b7f650e9351710faaab0aa2360cf503 100644 (file)
@@ -87,6 +87,8 @@ class TestGenericStringIO(unittest.TestCase):
             eq(line, self._line + '\n')
             i += 1
         eq(i, 5)
+        self._fp.close()
+        self.assertRaises(ValueError, self._fp.next)
 
 class TestStringIO(TestGenericStringIO):
     MODULE = StringIO