[New-bugs-announce] [issue4762] PyFile_FromFd() doesn't set the file name

STINNER Victor report at bugs.python.org
Sun Dec 28 17:57:09 CET 2008


New submission from STINNER Victor <victor.stinner at haypocalc.com>:

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.

----------
components: None
messages: 78419
nosy: haypo
severity: normal
status: open
title: PyFile_FromFd() doesn't set the file name
type: behavior
versions: Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4762>
_______________________________________


More information about the New-bugs-announce mailing list