Issue4762
Created on 2008-12-28 16:57 by vstinner, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg78419 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2008-12-28 16:57 | |
PyFile_FromFd() never changes the name of new created file object: $ ./python -c "import sys; print(sys.stdout.buffer.name, sys.stdout.name)" 0 0 Expected result: <stdout> <stdout>. --- Binary mode: - with buffering == 0, the file object is a FileIO. Changing the name can be done with: file._name=new_name - with buffering != 0, the file object is a BufferedXXX() and file.raw is a FileIO. So we have to set: file.raw._name=new_name If text mode, the file object is a TextIOWrapper and file.raw is a BufferedXXX() (buffering=0 is forbidden for text file). So changing the name can be done with: file.raw.raw._name=newname. I'm not sure of the classes/types. Note: PyFile_FromFd() shouldn't use PyErr_Clear() if changing the name fails. |
|||
| msg78421 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2008-12-28 17:05 | |
In my last patch to fix the issue #4705, I replaced PyFile_FromFd() by custom code which set correctly the file name. PyFile_FromFd() is also used in: - _Py_DisplaySourceLine(): name is not used, only PyFile_GetLine(file) - call_find_module() (imp.find_module()): return the file object with the wrong name Example with imp: >>> file, filename, extra = imp.find_module("os") >>> file <io.TextIOWrapper object at 0xb7b6ea6c> >>> file.name 4 >>> filename '/home/SHARE/SVN/py3k/Lib/os.py' |
|||
| msg78422 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2008-12-28 17:06 | |
> In my last patch to fix the issue #4705, I replaced PyFile_FromFd() > by custom code which set correctly the file name. The standard I/O: sys.stdin, sys.stdout and sys.stderr. |
|||
| msg84132 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2009-03-25 00:06 | |
In py3k, standard streams' names are now correct (since the io-c
merge):
Python 3.1a1+ (py3k:70589M, Mar 25 2009, 01:01:13)
>>> import sys
>>> sys.stdin.name, sys.stdout.name, sys.stderr.name
('<stdin>', '<stdout>', '<stderr>')
The last problem occurs with imp.find_module(). But imp.find_module()
also returns a "filename" argument, so I don't think that the issue
really matters. Let's close it ;-)
|
|||
| msg113772 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2010-08-13 13:36 | |
r83973 ignores the name argument of PyFile_FromFd() because it was already ignored (it did always produce an error). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:43 | admin | set | github: 49012 |
| 2010-08-13 13:36:35 | vstinner | set | messages: + msg113772 |
| 2009-03-25 00:06:58 | vstinner | set | status: open -> closed resolution: wont fix messages: + msg84132 |
| 2008-12-28 17:06:58 | vstinner | set | nosy: + pitrou |
| 2008-12-28 17:06:35 | vstinner | set | messages: + msg78422 |
| 2008-12-28 17:05:09 | vstinner | set | messages: + msg78421 |
| 2008-12-28 16:57:09 | vstinner | create | |
