summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-11-05 19:30:32 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-11-05 19:30:32 (GMT)
commitecc42a2b82858763818484572dccc7e88a3bdda1 (patch)
treea8bad97b03850ab5ccbe33e14332e4840b409816 /Modules
parentb37509b11b34fb4b2045162b88d4fa110cd4692b (diff)
downloadcpython-ecc42a2b82858763818484572dccc7e88a3bdda1.zip
cpython-ecc42a2b82858763818484572dccc7e88a3bdda1.tar.gz
cpython-ecc42a2b82858763818484572dccc7e88a3bdda1.tar.bz2
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
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_fileio.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index a946ea5..2cec213 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -61,10 +61,7 @@ static PyObject *
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 @@ get_closed(PyFileIOObject *self, void *closure)
}
static PyObject *
+get_closefd(PyFileIOObject *self, void *closure)
+{
+ return PyBool_FromLong((long)(self->closefd));
+}
+
+static PyObject *
get_mode(PyFileIOObject *self, void *closure)
{
return PyUnicode_FromString(mode_string(self));
@@ -828,6 +831,8 @@ get_mode(PyFileIOObject *self, void *closure)
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},
};