summaryrefslogtreecommitdiffstats
path: root/Lib/fileinput.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2019-04-29 14:55:39 (GMT)
committerGitHub <noreply@github.com>2019-04-29 14:55:39 (GMT)
commitbe6dbfb43b89989ccc83fbc4c5234f50f44c47ad (patch)
tree421acfea7d743934f09a3ed793a49914ed05bb05 /Lib/fileinput.py
parent88c093705615c50c47fdd9ab976803f73de7e308 (diff)
downloadcpython-be6dbfb43b89989ccc83fbc4c5234f50f44c47ad.zip
cpython-be6dbfb43b89989ccc83fbc4c5234f50f44c47ad.tar.gz
cpython-be6dbfb43b89989ccc83fbc4c5234f50f44c47ad.tar.bz2
bpo-1613500: Don't hardcode output file mode in fileinput.FileInput (GH-12986)
Diffstat (limited to 'Lib/fileinput.py')
-rw-r--r--Lib/fileinput.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/fileinput.py b/Lib/fileinput.py
index 4a71cc5..0764aa5 100644
--- a/Lib/fileinput.py
+++ b/Lib/fileinput.py
@@ -222,6 +222,7 @@ class FileInput:
warnings.warn("'U' mode is deprecated",
DeprecationWarning, 2)
self._mode = mode
+ 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")
@@ -348,14 +349,14 @@ class FileInput:
try:
perm = os.fstat(self._file.fileno()).st_mode
except OSError:
- self._output = open(self._filename, "w")
+ self._output = open(self._filename, self._write_mode)
else:
mode = os.O_CREAT | os.O_WRONLY | os.O_TRUNC
if hasattr(os, 'O_BINARY'):
mode |= os.O_BINARY
fd = os.open(self._filename, mode, perm)
- self._output = os.fdopen(fd, "w")
+ self._output = os.fdopen(fd, self._write_mode)
try:
os.chmod(self._filename, perm)
except OSError: