Dima Tisnek added the comment:

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()

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21191>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to