cpython: 9cf9527358a5 (original) (raw)

Mercurial > cpython

changeset 77954:9cf9527358a5 3.2

Issue #15247: FileIO now raises an error when given a file descriptor pointing to a directory. [#15247]

Antoine Pitrou solipsis@pitrou.net
date Fri, 06 Jul 2012 18:48:24 +0200
parents c97d78415f5a
children 19bd61ed3b3b 5020afc0b7c9
files Lib/test/test_fileio.py Misc/NEWS Modules/_io/fileio.c
diffstat 3 files changed, 16 insertions(+), 12 deletions(-)[+] [-] Lib/test/test_fileio.py 8 Misc/NEWS 3 Modules/_io/fileio.c 17

line wrap: on

line diff

--- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -127,6 +127,14 @@ class AutoFileTests(unittest.TestCase): else: self.fail("Should have raised IOError")

+ #A set of functions testing that we get expected behaviour if someone has #manually closed the internal file descriptor. First, a decorator: def ClosedFD(func):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -87,6 +87,9 @@ Core and Builtins Library ------- +- Issue #15247: FileIO now raises an error when given a file descriptor

--- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -166,22 +166,15 @@ fileio_new(PyTypeObject *type, PyObject directories, so we need a check. / static int -dircheck(fileio self, const char name) +dircheck(fileio self, PyObject *nameobj) { #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) struct stat buf; if (self->fd < 0) return 0; if (fstat(self->fd, &buf) == 0 && S_ISDIR(buf.st_mode)) {

-

#endif @@ -373,9 +366,9 @@ fileio_init(PyObject *oself, PyObject *a PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); goto error; }

#if defined(MS_WINDOWS) || defined(CYGWIN) /* don't translate newlines (\r\n <=> \n) */