]> granicus.if.org Git - python/commitdiff
raise an ValueError in getvalue() on closed StringIO (closes #12161)
authorBenjamin Peterson <benjamin@python.org>
Thu, 26 May 2011 14:56:41 +0000 (09:56 -0500)
committerBenjamin Peterson <benjamin@python.org>
Thu, 26 May 2011 14:56:41 +0000 (09:56 -0500)
Thanks for Catalin Iacob for the patch.

Lib/StringIO.py
Lib/test/test_StringIO.py
Misc/ACKS
Misc/NEWS

index 340fae1229031c7110d18d5d6e143f7b9d106d1a..f74a066773fec986cc39acc9bdd8bebbd2bcc0b5 100644 (file)
@@ -266,6 +266,7 @@ class StringIO:
         8th bit) will cause a UnicodeError to be raised when getvalue()
         is called.
         """
+        _complain_ifclosed(self.closed)
         if self.buflist:
             self.buf += ''.join(self.buflist)
             self.buflist = []
index 4774c6dbf19238ec96b08c549e8bcb1aaf0dd136..76fc3d76e101de4c540e88e9818ea202b96fc69e 100644 (file)
@@ -100,6 +100,10 @@ class TestGenericStringIO(unittest.TestCase):
         self._fp.close()
         self.assertRaises(ValueError, self._fp.next)
 
+    def test_getvalue(self):
+        self._fp.close()
+        self.assertRaises(ValueError, self._fp.getvalue)
+
 class TestStringIO(TestGenericStringIO):
     MODULE = StringIO
 
index 164473f139f3636285f747a161aecbe27f905afc..0066b3273a62f9f99601cdba4e3848f1ff446233 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -382,6 +382,7 @@ Eric Huss
 Jeremy Hylton
 Gerhard Häring
 Fredrik Håård
+Catalin Iacob
 Mihai Ibanescu
 Lars Immisch
 Bobby Impollonia
index e34bd486195462a533a4dbc7adb00315cf0fe746..ae2b5fa53a8d018d34ed80ea6762351f93092d1c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #12161: Cause StringIO.getvalue() to raise a ValueError when used on a
+  closed StringIO instance.
+
 - Issue #12182: Fix pydoc.HTMLDoc.multicolumn() if Python uses the new (true)
   division (python -Qnew). Patch written by Ralf W. Grosse-Kunstleve.