Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6203d8f

Browse files
committed
Patch 1341 by Amaury Forgeot d'Arc.
This patch corrects test_fileinput on Windows: when redirecting stdout, os.open should be given O_BINARY, because the file descriptor is then wrapped in a text-mode file; os.fdopen(fd, "w").
1 parent 3db4686 commit 6203d8f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/fileinput.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,11 @@ def readline(self):
326326
except OSError:
327327
self._output = open(self._filename, "w")
328328
else:
329-
fd = os.open(self._filename,
330-
os.O_CREAT | os.O_WRONLY | os.O_TRUNC,
331-
perm)
329+
mode = os.O_CREAT | os.O_WRONLY | os.O_TRUNC
330+
if hasattr(os, 'O_BINARY'):
331+
mode |= os.O_BINARY
332+
333+
fd = os.open(self._filename, mode, perm)
332334
self._output = os.fdopen(fd, "w")
333335
try:
334336
if hasattr(os, 'chmod'):

0 commit comments

Comments
 (0)