From c6d301734a460128524e79fa0acb5cac2bcd3260 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 26 May 2011 09:56:41 -0500 Subject: raise an ValueError in getvalue() on closed StringIO (closes #12161) Thanks for Catalin Iacob for the patch. --- Lib/StringIO.py | 1 + Lib/test/test_StringIO.py | 4 ++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ 4 files changed, 9 insertions(+) diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 340fae1229..f74a066773 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -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 = [] diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index 4774c6dbf1..76fc3d76e1 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -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 diff --git a/Misc/ACKS b/Misc/ACKS index 164473f139..0066b3273a 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index e34bd48619..ae2b5fa53a 100644 --- 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. -- cgit v1.2.1