summaryrefslogtreecommitdiffstats
path: root/Lib/fileinput.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-03-04 17:50:22 (GMT)
committerGitHub <noreply@github.com>2020-03-04 17:50:22 (GMT)
commit942f7a2dea2e95a0fa848329565c0d0288d92e47 (patch)
tree31abda8d45ef676a46ea63a6a8a61ccf6061e9c5 /Lib/fileinput.py
parent00c77ae55a82548a6b45af73cdf712ea34910645 (diff)
downloadcpython-942f7a2dea2e95a0fa848329565c0d0288d92e47.zip
cpython-942f7a2dea2e95a0fa848329565c0d0288d92e47.tar.gz
cpython-942f7a2dea2e95a0fa848329565c0d0288d92e47.tar.bz2
bpo-39674: Revert "bpo-37330: open() no longer accept 'U' in file mode (GH-16959)" (GH-18767)
This reverts commit e471e72977c83664f13d041c78549140c86c92de. The mode will be removed from Python 3.10.
Diffstat (limited to 'Lib/fileinput.py')
-rw-r--r--Lib/fileinput.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/fileinput.py b/Lib/fileinput.py
index 166c631..c1b0ec9 100644
--- a/Lib/fileinput.py
+++ b/Lib/fileinput.py
@@ -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")