]> granicus.if.org Git - python/commitdiff
SF patch #1359365: cStringIO.StringIO.isatty() will raise a ValueError
authorWalter Dörwald <walter@livinglogic.de>
Wed, 15 Mar 2006 22:13:13 +0000 (22:13 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Wed, 15 Mar 2006 22:13:13 +0000 (22:13 +0000)
now if close() has been called before (like file and StringIO.StringIO do)

Lib/test/test_StringIO.py
Misc/NEWS
Modules/cStringIO.c

index a2e544458b7f650e9351710faaab0aa2360cf503..cc3367fed8d16bdfa9a4b0c68c8b0832576fbf32 100644 (file)
@@ -75,6 +75,13 @@ class TestGenericStringIO(unittest.TestCase):
         f.close()
         self.assertEqual(f.closed, True)
 
+    def test_isatty(self):
+        f = self.MODULE.StringIO()
+        self.assertRaises(TypeError, f.isatty, None)
+        self.assertEqual(f.isatty(), False)
+        f.close()
+        self.assertRaises(ValueError, f.isatty)
+
     def test_iterator(self):
         eq = self.assertEqual
         unless = self.failUnless
index 47da68c173ebf4662d6ade94319b2c1434578abb..820ae4a481cbb12942303fd346c92521228815b1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -449,6 +449,9 @@ Library
   codecs.getincrementaldecoder() and codecs.getincrementalencoder() have
   been added.
 
+- SF patch #1359365: cStringIO.StringIO.isatty() will raise a ValueError
+  now if close() has been called before (like file and StringIO.StringIO do)
+
 - A regrtest option -w was added to re-run failed tests in verbose mode.
 
 - Patch #1446372: quit and exit can now be called from the interactive
index fd28aa9324dee17cce77eb5612b653f9a7fc401d..bdc9f00d39d3e3c4294b57a9fd201ab5dac13431 100644 (file)
@@ -144,7 +144,8 @@ PyDoc_STRVAR(IO_isatty__doc__, "isatty(): always returns 0");
 
 static PyObject *
 IO_isatty(IOobject *self, PyObject *unused) {
-       Py_INCREF(Py_False);
+        if (!IO__opencheck(self)) return NULL;
+        Py_INCREF(Py_False);
         return Py_False;
 }