]> granicus.if.org Git - python/commitdiff
Patch 1341 by Amaury Forgeot d'Arc.
authorGuido van Rossum <guido@python.org>
Mon, 29 Oct 2007 17:39:59 +0000 (17:39 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 29 Oct 2007 17:39:59 +0000 (17:39 +0000)
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").

Lib/fileinput.py

index 0d7ffada8c74a9e5ef2361696390eb15eb95ef23..e4c71ced6d937f526690570852b2100ad7eb4c07 100644 (file)
@@ -326,9 +326,11 @@ class FileInput:
                     except OSError:
                         self._output = open(self._filename, "w")
                     else:
-                        fd = os.open(self._filename,
-                                     os.O_CREAT | os.O_WRONLY | os.O_TRUNC,
-                                     perm)
+                        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")
                         try:
                             if hasattr(os, 'chmod'):