[ python-Bugs-967182 ] file("foo", "wU") is silently accepted

SourceForge.net noreply at sourceforge.net
Mon Jun 7 23:01:44 EDT 2004


Bugs item #967182, was opened at 2004-06-05 13:15
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=967182&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Skip Montanaro (montanaro)
Assigned to: Skip Montanaro (montanaro)
Summary: file("foo", "wU") is silently accepted

Initial Comment:
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.


----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2004-06-07 23:01

Message:
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.

----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2004-06-07 22:10

Message:
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?)


----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2004-06-05 15:51

Message:
Logged In: YES 
user_id=44345

Here's a first cut patch - test suite fails though - must be 
something obvious...

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=967182&group_id=5470



More information about the Python-bugs-list mailing list