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 amaury.forgeotdarc
Recipients amaury.forgeotdarc, benjamin.peterson
Date 2008-11-22.00:13:16
SpamBayes Score 9.098611e-06
Marked as misclassified No
Message-id <1227312799.3.0.532336276837.issue4386@psf.upfronthosting.co.za>
In-reply-to
Content
The changes following r67300 introduced the .mode and .name attributes on all 
the file-like objects returned by the open() function.

This also changed the mode returned by a file opened in binary mode: it was 
"rb", now it is "r". The fact that the mode does not "round-trip" (i.e: open(f, 
mode).mode != mode) was considered not important.

But now it is difficult to see if some opened file was opened in text or binary 
mode; in test_gzip.py, a test had to be changed, and now it does not test 
anything at all: the intent of the test is just to verify that a zip file is 
always opened in binary mode.

Benjamin suggested to change the mode returned by FileIO objects, so that they 
always contain a 'b'. They also accept an extra 'b' on creation: it is just 
ignored.

Now, for a file opened in text mode:
>>> f = open('filename')
>>> assert f.mode            == 'r'
>>> assert f.buffer.mode     == 'rb'
>>> assert f.buffer.raw.mode == 'rb'

The mode attribute is now always consistent with the one passed to the open() 
function. This also avoid gratuitous breakage with python2.x.

Patch attached. All tests pass.
History
Date User Action Args
2008-11-22 00:13:20amaury.forgeotdarcsetrecipients: + amaury.forgeotdarc, benjamin.peterson
2008-11-22 00:13:19amaury.forgeotdarcsetmessageid: <1227312799.3.0.532336276837.issue4386@psf.upfronthosting.co.za>
2008-11-22 00:13:18amaury.forgeotdarclinkissue4386 messages
2008-11-22 00:13:17amaury.forgeotdarccreate