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 benjamin.peterson
Recipients Dima.Tisnek, benjamin.peterson, python-dev
Date 2014-04-14.04:05:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397448327.30888.106122481.2D34C162@webmail.messagingengine.com>
In-reply-to <1397209220.11.0.00351625682393.issue21191@psf.upfronthosting.co.za>
Content
Feel free to submit a patch.

On Fri, Apr 11, 2014, at 2:40, Dima Tisnek wrote:
> 
> 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.

Well, you just have check exactly what it's checking now, which seems to
be !S_ISDIR.

> 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...

Yes, this is one of the main problems.

> 
> 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-14 04:05:29benjamin.petersonsetrecipients: + benjamin.peterson, python-dev, Dima.Tisnek
2014-04-14 04:05:29benjamin.petersonlinkissue21191 messages
2014-04-14 04:05:29benjamin.petersoncreate