[Python-3000-checkins] r58704 - python/branches/py3k/Lib/fileinput.py

guido.van.rossum python-3000-checkins at python.org
Mon Oct 29 18:39:59 CET 2007


Author: guido.van.rossum
Date: Mon Oct 29 18:39:59 2007
New Revision: 58704

Modified:
   python/branches/py3k/Lib/fileinput.py
Log:
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").


Modified: python/branches/py3k/Lib/fileinput.py
==============================================================================
--- python/branches/py3k/Lib/fileinput.py	(original)
+++ python/branches/py3k/Lib/fileinput.py	Mon Oct 29 18:39:59 2007
@@ -326,9 +326,11 @@
                     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'):


More information about the Python-3000-checkins mailing list