Message193585
Currently, if a byte sequence is passed to open() as the file name, the resulting file will have that object as its name:
>>> open(os.path.expanduser(b"~/.hgrc"))
<_io.TextIOWrapper name=b'/home/ncoghlan/.hgrc' mode='r' encoding='UTF-8'>
>>> open(os.path.expanduser("~/.hgrc"))
<_io.TextIOWrapper name='/home/ncoghlan/.hgrc' mode='r' encoding='UTF-8'>
As documented in a recent post from Armin Ronacher [1], this causes the "bytes" to leak out to the public API of the file, causing problems since user code can't assume that "f.name" is a string.
When bytes are passed to open() as the filename, os.fsdecode should be used to convert them to a text string before storing them in the name attribute.
[1] http://lucumr.pocoo.org/2013/7/2/the-updated-guide-to-unicode/ |
|
Date |
User |
Action |
Args |
2013-07-23 05:06:58 | ncoghlan | set | recipients:
+ ncoghlan, vstinner |
2013-07-23 05:06:58 | ncoghlan | set | messageid: <1374556018.34.0.468152457131.issue18534@psf.upfronthosting.co.za> |
2013-07-23 05:06:58 | ncoghlan | link | issue18534 messages |
2013-07-23 05:06:57 | ncoghlan | create | |
|