mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-39674: Revert "bpo-37330: open() no longer accept 'U' in file mode (GH-16959)" (GH-18767)
This reverts commit e471e72977
.
The mode will be removed from Python 3.10.
This commit is contained in:
parent
00c77ae55a
commit
942f7a2dea
13 changed files with 99 additions and 54 deletions
|
@ -209,10 +209,15 @@ class FileInput:
|
|||
self._isstdin = False
|
||||
self._backupfilename = None
|
||||
# restrict mode argument to reading modes
|
||||
if mode not in ('r', 'rb'):
|
||||
raise ValueError("FileInput opening mode must be 'r' or 'rb'")
|
||||
if mode not in ('r', 'rU', 'U', 'rb'):
|
||||
raise ValueError("FileInput opening mode must be one of "
|
||||
"'r', 'rU', 'U' and 'rb'")
|
||||
if 'U' in mode:
|
||||
import warnings
|
||||
warnings.warn("'U' mode is deprecated",
|
||||
DeprecationWarning, 2)
|
||||
self._mode = mode
|
||||
self._write_mode = mode.replace('r', 'w')
|
||||
self._write_mode = mode.replace('r', 'w') if 'U' not in mode else 'w'
|
||||
if openhook:
|
||||
if inplace:
|
||||
raise ValueError("FileInput cannot use an opening hook in inplace mode")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue