changeset 40315:431a831342d2

py3: work around unicode stdio streams in contrib/hgclient.py
author Yuya Nishihara <yuya@tcha.org>
date Tue, 16 Oct 2018 07:08:12 +0200
parents 73c2b9c9cd3c
children 09540a5f0a15
files contrib/hgclient.py
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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)