bpo-39674: Revert "bpo-37330: open() no longer accept 'U' in file mode (GH-16959)" by vstinner · Pull Request #18767 · python/cpython
The default mode is 'rt' (open for reading text). For binary random
'U' mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.
buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate
int creating = 0, reading = 0, writing = 0, appending = 0, updating = 0; int text = 0, binary = 0; int text = 0, binary = 0, universal = 0;
char rawmode[6], *m; int line_buffering, is_number;
/* Parameters validation */ if (universal) { if (creating || writing || appending || updating) { PyErr_SetString(PyExc_ValueError, "mode U cannot be combined with 'x', 'w', 'a', or '+'"); goto error; } if (PyErr_WarnEx(PyExc_DeprecationWarning, "'U' mode is deprecated", 1) < 0) goto error; reading = 1; }
if (text && binary) { PyErr_SetString(PyExc_ValueError, "can't have text and binary mode at once");