[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2021-10-21 Thread Christian Heimes


Christian Heimes  added the comment:

Fine with me! Thanks for your feedback.

--
resolution:  -> rejected
stage: needs patch -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2021-10-21 Thread STINNER Victor


STINNER Victor  added the comment:

I like calling .fileno() explicitly. It seems like it's not really needed to 
call it implicitly, since this issue doesn't get much activity. I suggest to 
reject it.

--
status: pending -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2021-10-21 Thread Christian Heimes


Christian Heimes  added the comment:

Victor, do we want to support "with open("somefile") as f: os.chmod(f, 0o644)"? 
The feature request has been languishing for 8 years.

--
status: open -> pending
versions: +Python 3.11 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2013-06-21 Thread Christian Heimes

New submission from Christian Heimes:

I suggest that posixpath.c:_fd_converter() should  PyObject_AsFileDescriptor() 
to convert a Python object to a fd integer. With PyObject_AsFileDescriptor() 
functions such as os.chmod() can be called with an opened file as first 
argument:

Now:

  with open(somefile) as f:
 os.chmod(f.fileno(), 0o644)

With PyObject_AsFileDescriptor():

with open(somefile) as f:
 os.chmod(f, 0o644)

_fd_converter() also has more elaborate overflow checks. These checks should be 
added to PyObject_AsFileDescriptor(), too.

--
messages: 191563
nosy: christian.heimes
priority: normal
severity: normal
stage: needs patch
status: open
title: posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()
type: enhancement
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18276
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2013-06-21 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

Do we want the low-level os.write() to work with file objects, or sockets?

--
nosy: +amaury.forgeotdarc

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18276
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2013-06-21 Thread STINNER Victor

STINNER Victor added the comment:

This issue looks to be related to #18269.

--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18276
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2013-06-21 Thread Christian Heimes

Christian Heimes added the comment:

os.write() already works with file and sockets object but you have to call 
ob.fileno() first. The select module uses PyObject_AsFileDescriptor() all over 
the module to get the file descriptor number from file and socket objects.

Let's unify os' and select's behavior!

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18276
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2013-06-21 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

 Let's unify os' and select's behavior!
OK, let's do that on Windows first :-)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18276
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2013-06-21 Thread Christian Heimes

Christian Heimes added the comment:

 OK, let's do that on Windows first :-)

Gotcha :( Damn you winsock.dll!

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18276
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18276] posixpath.c:_fd_converter() should use PyObject_AsFileDescriptor()

2013-06-21 Thread STINNER Victor

STINNER Victor added the comment:

 OK, let's do that on Windows first :-)

For the PEP 433, I did something like that in os.get_cloexec() and 
os.set_cloexec():

http://hg.python.org/features/pep-433/file/f32c2b09f332/Modules/posixmodule.c#l10198

On Windows, I added two code paths: one for HANDLE (to support sockets), one 
for file descriptors (classic files). It means that you need a C function 
supports HANDLE as input type, rather than int (file descriptor).

Can't we raise a nice error message when we get a socket, whereas the function 
does not support HANDLE? What is the current message on Windows when passing 
sock.fileno() to a function expecting a file descriptor? Would it be worse if 
Python implictly call .fileno() on a socket?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18276
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com