classification
Title: A binary file should show "b" in its mode
Type: behavior Stage: patch review
Components: Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: amaury.forgeotdarc, benjamin.peterson
Priority: release blocker Keywords: needs review, patch

Created on 2008-11-22 00:13 by amaury.forgeotdarc, last changed 2008-11-22 00:42 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
fileio_mode.patch amaury.forgeotdarc, 2008-11-22 00:13
Messages (2)
msg76225 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-11-22 00:13
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.
msg76227 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-11-22 00:42
Amaury, thanks for getting the tests to pass. Applied in r67325.
History
Date User Action Args
2008-11-22 00:42:13benjamin.petersonsetstatus: open -> closed
resolution: accepted
messages: + msg76227
2008-11-22 00:13:18amaury.forgeotdarccreate