Mercurial > cpython-lru_cache-weakref
diff Modules/_fileio.c @ 49783:eade47dfc1e4 legacy-trunk
Fixed issue #4233.
Changed semantic of _fileio.FileIO's close() method on file objects with closefd=False.
The file descriptor is still kept open but the file object behaves like a closed file.
The FileIO object also got a new readonly attribute closefd.
Approved by Barry
Backport of r67106 from the py3k branch
| author | Amaury Forgeot d'Arc <amauryfa@gmail.com> |
|---|---|
| date | Thu, 20 Nov 2008 23:34:31 +0000 |
| parents | 6a20e8c1745a |
| children | dc4acf753296 |
line wrap: on
line diff
--- a/Modules/_fileio.c Thu Nov 20 22:06:22 2008 +0000 +++ b/Modules/_fileio.c Thu Nov 20 23:34:31 2008 +0000 @@ -61,10 +61,7 @@ fileio_close(PyFileIOObject *self) { if (!self->closefd) { - if (PyErr_WarnEx(PyExc_RuntimeWarning, - "Trying to close unclosable fd!", 3) < 0) { - return NULL; - } + self->fd = -1; Py_RETURN_NONE; } errno = internal_close(self); @@ -821,6 +818,12 @@ } static PyObject * +get_closefd(PyFileIOObject *self, void *closure) +{ + return PyBool_FromLong((long)(self->closefd)); +} + +static PyObject * get_mode(PyFileIOObject *self, void *closure) { return PyString_FromString(mode_string(self)); @@ -828,6 +831,8 @@ static PyGetSetDef fileio_getsetlist[] = { {"closed", (getter)get_closed, NULL, "True if the file is closed"}, + {"closefd", (getter)get_closefd, NULL, + "True if the file descriptor will be closed"}, {"mode", (getter)get_mode, NULL, "String giving the file mode"}, {0}, };
