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.

classification
Title: file("foo", "wU") is silently accepted
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: skip.montanaro Nosy List: skip.montanaro, tim.peters
Priority: normal Keywords:

Created on 2004-06-05 17:15 by skip.montanaro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fileobj.diff skip.montanaro, 2004-06-11 05:44
Messages (6)
msg21040 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2004-06-05 17:15
PEP 278 says at opening a file with "wU" is illegal, yet
file("foo", "wU") passes without complaint.  There may
be other flags which the PEP disallows with "U" that need
to be checked.
msg21041 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2004-06-05 19:51
Logged In: YES 
user_id=44345

Here's a first cut patch - test suite fails though - must be 
something obvious...
msg21042 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2004-06-08 02:10
Logged In: YES 
user_id=44345

Turned out not to be obvious at all (and not related to my
changes).  Here's another patch which is cleaner I think.

Would someone take a look at this?  My intent is to not
let invalid modes pass silently (as "wU" currently does).
Have I accounted for all the valid mode strings? It has
some semantic changes, so this is not a backport
candidate.

I'm not sure about how 't' is handled.  It's only of use on
Windows as I understand it, but I don't see it sucked out
of the mode string on non-Windows platforms, so it must
be silently accepted on Unix and Mac.  (Can someone
confirm this?)
msg21043 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-06-08 03:01
Logged In: YES 
user_id=31435

The C standard is open-ended about what a mode string can 
contain, and Python has historically allowed users to exploit 
platform-specific extensions here.  On Windows, at least 't' 
and 'c' mean something in mode strings, and 'c' is actually 
useful (it forces writes to get committed to disk 
immediately).  Most platforms ignore characters in mode 
strings that they don't understand.  This is an exhaustive list 
of the mode strings a conforming C implementation must 
support (from C99):

"""
r open text file for reading
w truncate to zero length or create text file for writing
a append; open or create text file for writing at end-of-file
rb open binary file for reading
wb truncate to zero length or create binary file for writing
ab append; open or create binary file for writing at end-of-file
r+ open text file for update (reading and writing)
w+ truncate to zero length or create text file for update
a+ append; open or create text file for update, writing at end-
of-file
r+b or rb+ open binary file for update (reading and writing)
w+b or wb+ truncate to zero length or create binary file for 
update
a+b or ab+ append; open or create binary file for update, 
writing at end-of-file
"""

Implementations are free to support as many more as they 
care to.

Guido may be in favor of restricting Python (in 2.4 or 2.5) to 
the set of mode strings required by C99, plus those that 
make sense with Python's U extension.  I think he said 
something to that effect in person once.  But 'c' is in fact 
useful on Windows, and code will break if it's outlawed.
msg21044 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2004-06-11 05:44
Logged In: YES 
user_id=44345

So this means I can't be explicit about what to accept, only about
what to reject.  Simpler patch attached...
msg21045 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2005-05-20 03:08
Logged In: YES 
user_id=44345

This has been idle for nearly a year with no further response.
Looks good to me. ;-)

Objects/fileobject.c 2.194
Lib/test/test_file.py 1.16
History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40351
2004-06-05 17:15:42skip.montanarocreate