diff options
author | Raymond Hettinger <python@rcn.com> | 2003-08-08 12:20:03 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-08-08 12:20:03 (GMT) |
commit | 5475f2394abea43c541d8660ed91af920634add5 (patch) | |
tree | 714500f4e60cfc6950b1f9303bdd9da964e98795 | |
parent | 6e13bcc7b187aff61628120fa58e5cee2ae32f68 (diff) | |
download | cpython-5475f2394abea43c541d8660ed91af920634add5.zip cpython-5475f2394abea43c541d8660ed91af920634add5.tar.gz cpython-5475f2394abea43c541d8660ed91af920634add5.tar.bz2 |
SF bug #770485: cStringIO does not set closed attr
-rw-r--r-- | Lib/test/test_StringIO.py | 10 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/cStringIO.c | 24 |
3 files changed, 34 insertions, 2 deletions
diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index 8c367e8..c318eaa 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -55,6 +55,16 @@ class TestGenericStringIO(unittest.TestCase): f.close() self.assertRaises(ValueError, f.write, 'frobnitz') + def test_closed_flag(self): + f = self.MODULE.StringIO() + self.assertEqual(f.closed, False) + f.close() + self.assertEqual(f.closed, True) + f = self.MODULE.StringIO("abc") + self.assertEqual(f.closed, False) + f.close() + self.assertEqual(f.closed, True) + def test_iterator(self): eq = self.assertEqual unless = self.failUnless @@ -18,6 +18,8 @@ Core and builtins Extension modules ----------------- +- cStringIO now supports the f.closed attribute. + - The signal module now exposes SIGRTMIN and SIGRTMAX (if available). Library diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index bc23c77..ac84ab0 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -88,6 +88,22 @@ IO__opencheck(IOobject *self) { } static PyObject * +IO_get_closed(IOobject *self, void *closure) +{ + PyObject *result = Py_False; + + if (self->buf == NULL) + result = Py_True; + Py_INCREF(result); + return result; +} + +static PyGetSetDef file_getsetlist[] = { + {"closed", (getter)IO_get_closed, NULL, "True if the file is closed"}, + {0}, +}; + +static PyObject * IO_flush(IOobject *self, PyObject *unused) { UNLESS (IO__opencheck(self)) return NULL; @@ -455,6 +471,7 @@ static struct PyMethodDef O_methods[] = { static PyMemberDef O_memberlist[] = { {"softspace", T_INT, offsetof(Oobject, softspace), 0, "flag indicating that a space needs to be printed; used by print"}, + /* getattr(f, "closed") is implemented without this table */ {NULL} /* Sentinel */ }; @@ -498,7 +515,8 @@ static PyTypeObject Otype = { PyObject_SelfIter, /*tp_iter */ (iternextfunc)IO_iternext, /*tp_iternext */ O_methods, /*tp_methods */ - O_memberlist /*tp_members */ + O_memberlist, /*tp_members */ + file_getsetlist, /*tp_getset */ }; static PyObject * @@ -614,7 +632,9 @@ static PyTypeObject Itype = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)IO_iternext, /* tp_iternext */ - I_methods /* tp_methods */ + I_methods, /* tp_methods */ + 0, /* tp_members */ + file_getsetlist, /* tp_getset */ }; static PyObject * |