From patchwork Tue Oct 16 07:26:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 6] py3: work around unicode stdio streams in contrib/hgclient.py From: Yuya Nishihara X-Patchwork-Id: 36025 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Tue, 16 Oct 2018 09:26:41 +0200 # HG changeset patch # User Yuya Nishihara # 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 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)