diff --git a/External/Tools/Notepad2.exe b/External/Tools/Notepad2.exe deleted file mode 100644 index 2a29d3a42a..0000000000 Binary files a/External/Tools/Notepad2.exe and /dev/null differ diff --git a/Languages/IronPython/IronPython/Runtime/PythonFile.cs b/Languages/IronPython/IronPython/Runtime/PythonFile.cs index 167fef355b..e8f58fb792 100644 --- a/Languages/IronPython/IronPython/Runtime/PythonFile.cs +++ b/Languages/IronPython/IronPython/Runtime/PythonFile.cs @@ -1217,23 +1217,24 @@ private static void TranslateAndValidateMode(string mode, out FileMode fmode, ou mode = "r+"; } else if (mode[0] == 'w' || mode[0] == 'a') { throw PythonOps.ValueError("universal newline mode can only be used with modes starting with 'r'"); - } else { + } else if (mode[0] != 'r') { mode = "r" + mode; } } - // process read/write/append + // process read/write/append and remove char from mode seekEnd = false; switch (mode[0]) { - case 'r': fmode = FileMode.Open; break; - case 'w': fmode = FileMode.Create; break; - case 'a': fmode = FileMode.Append; break; + case 'r': fmode = FileMode.Open; mode = mode.Remove(0, 1); break; + case 'w': fmode = FileMode.Create; mode = mode.Remove(0, 1); break; + case 'a': fmode = FileMode.Append; mode = mode.Remove(0, 1); break; default: throw PythonOps.ValueError("mode string must begin with one of 'r', 'w', 'a' or 'U', not '{0}'", inMode); } // process + if (mode.IndexOf('+') != -1) { + mode = mode.Remove(mode.IndexOf('+'), 1); faccess = FileAccess.ReadWrite; if (fmode == FileMode.Append) { fmode = FileMode.OpenOrCreate; @@ -1247,6 +1248,13 @@ private static void TranslateAndValidateMode(string mode, out FileMode fmode, ou default: throw new InvalidOperationException(); } } + + // Make some additional mode check after processing all valid modes. + if (mode.Length > 0) { + if (mode[0] != 'U' && mode[0] != 'b' && mode[0] != 't') { + throw PythonOps.ValueError("Invalid mode ('{0}')", inMode); + } + } } public void __init__(CodeContext/*!*/ context, [NotNull]Stream/*!*/ stream) {