This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dima.Tisnek
Recipients Dima.Tisnek, benjamin.peterson, python-dev
Date 2014-04-11.09:40:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397209220.11.0.00351625682393.issue21191@psf.upfronthosting.co.za>
In-reply-to
Content
I think consistency between Python versions is just as important as consistency between fd types.

Here's my hack quickfix outline:

fd = os.open(...)
try:
    if not stat.S_ISREG(os.fstat(fd).st_mode):
        raise OSError(None, "Not a regular file", ...)
    f = os.fdopen(fd, ...)
except EnvironmentError:
    os.close(fd)

Can something like this be implemented in os.py
There's already a check `if not isinstance(fd, int): raise ...`

Granted we'd have to get fd type check exactly right.
fdopen should probably succeed for regular files, pipes, char devices, block device, ptry's ...
fdopen should fail where underlying implementation fails, i.e. directories, sockets(?), epoll(?), timerfd(?)

There's a list at http://en.wikipedia.org/wiki/File_descriptor
I'm not sure about some types.

P.S. I wish there was a way to rescue fd from FILE*, but nothing like that seems to exist...

P.P.S. another option is to always use dup(), but that may break existing programs is they expect fd == fdopen(fd).fileno()
History
Date User Action Args
2014-04-11 09:40:20Dima.Tisneksetrecipients: + Dima.Tisnek, benjamin.peterson, python-dev
2014-04-11 09:40:20Dima.Tisneksetmessageid: <1397209220.11.0.00351625682393.issue21191@psf.upfronthosting.co.za>
2014-04-11 09:40:20Dima.Tisneklinkissue21191 messages
2014-04-11 09:40:18Dima.Tisnekcreate