py3: work around unicode stdio streams in contrib/hgclient.py
authorYuya Nishihara <yuya@tcha.org>
Tue, 16 Oct 2018 07:08:12 +0200
changeset 40315 431a831342d2
parent 40314 73c2b9c9cd3c
child 40316 09540a5f0a15
py3: work around unicode stdio streams in contrib/hgclient.py
contrib/hgclient.py
--- a/contrib/hgclient.py	Tue Oct 16 07:00:41 2018 +0200
+++ b/contrib/hgclient.py	Tue Oct 16 07:08:12 2018 +0200
@@ -16,6 +16,13 @@
     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 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 @@
                 return
 
 def check(func, connect=connectpipe):
-    sys.stdout.flush()
+    stdout.flush()
     server = connect()
     try:
         return func(server)