Bugs item #967182, was opened at 2004-06-05 12:15 Message generated for change (Comment added) made by montanaro You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=967182&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Interpreter Core Group: None >Status: Closed >Resolution: Fixed 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: Skip Montanaro (montanaro) Date: 2005-05-19 22:08 Message: 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 ---------------------------------------------------------------------- Comment By: Skip Montanaro (montanaro) Date: 2004-06-11 00:44 Message: 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... ---------------------------------------------------------------------- Comment By: Tim Peters (tim_one) Date: 2004-06-07 22: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 21: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 14: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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com