Patchwork [1,of,3] py3: conditionalize initialization of stdio flags

login
register
mail settings
Submitter Yuya Nishihara
Date March 3, 2018, 3:52 a.m.
Message ID <c0193f6ec467af81491d.1520049154@mimosa>
Download mbox | patch
Permalink /patch/28762/
State Accepted
Headers show

Comments

Yuya Nishihara - March 3, 2018, 3:52 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520046636 18000
#      Fri Mar 02 22:10:36 2018 -0500
# Node ID c0193f6ec467af81491d0e7c8c46fe0f676f3018
# Parent  a007db19dc4d889dda54014f8dd3eb8a1c1ef08b
py3: conditionalize initialization of stdio flags

Since Python 3 doesn't depend on the stdio of libc, there should be no need
to set O_BINARY flag on Windows.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -105,12 +105,15 @@  def run():
         # change the status code and move on.
         except IOError:
             status = -1
-
     sys.exit(status & 255)
 
-def _initstdio():
-    for fp in (sys.stdin, sys.stdout, sys.stderr):
-        util.setbinary(fp)
+if pycompat.ispy3:
+    def _initstdio():
+        pass
+else:
+    def _initstdio():
+        for fp in (sys.stdin, sys.stdout, sys.stderr):
+            util.setbinary(fp)
 
 def _getsimilar(symbols, value):
     sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio()