Patchwork [2,of,6] py3: work around unicode stdio streams in contrib/hgclient.py

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 16, 2018, 7:26 a.m.
Message ID <ec5c140cee73da79dc3f.1539674801@mimosa>
Download mbox | patch
Permalink /patch/36025/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 16, 2018, 7:26 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1539666492 -7200
#      Tue Oct 16 07:08:12 2018 +0200
# Node ID ec5c140cee73da79dc3f48c4e75991cf6e34b7cd
# Parent  0001bda2e00c73f9f82591d3ce7b44f552d0b936
py3: work around unicode stdio streams in contrib/hgclient.py

Patch

diff --git a/contrib/hgclient.py b/contrib/hgclient.py
--- a/contrib/hgclient.py
+++ b/contrib/hgclient.py
@@ -16,6 +16,13 @@  except ImportError:
     import io
     stringio = io.StringIO
 
+if sys.version_info[0] >= 3:
+    stdout = sys.stdout.buffer
+    stderr = sys.stderr.buffer
+else:
+    stdout = sys.stdout
+    stderr = sys.stderr
+
 def connectpipe(path=None):
     cmdline = [b'hg', b'serve', b'--cmdserver', b'pipe']
     if path:
@@ -81,10 +88,10 @@  def readchannel(server):
 def sep(text):
     return text.replace(b'\\', b'/')
 
-def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None,
+def runcommand(server, args, output=stdout, error=stderr, input=None,
                outfilter=lambda x: x):
     print(b'*** runcommand', b' '.join(args))
-    sys.stdout.flush()
+    stdout.flush()
     server.stdin.write(b'runcommand\n')
     writeblock(server, b'\0'.join(args))
 
@@ -114,7 +121,7 @@  def runcommand(server, args, output=sys.
                 return
 
 def check(func, connect=connectpipe):
-    sys.stdout.flush()
+    stdout.flush()
     server = connect()
     try:
         return func(server)