[PATCH 4 of 6] py3: rewrite StringIO fallback for Python 3

Yuya Nishihara yuya at tcha.org
Tue Oct 16 03:26:43 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1539669977 -7200
#      Tue Oct 16 08:06:17 2018 +0200
# Node ID a202f1b4611205a08a6730db63dfead59b69f42b
# Parent  94b452b2cfab5442a50b43daf3c6796c8ce8126b
py3: rewrite StringIO fallback for Python 3

diff --git a/contrib/hgclient.py b/contrib/hgclient.py
--- a/contrib/hgclient.py
+++ b/contrib/hgclient.py
@@ -1,6 +1,8 @@
 # A minimal client for Mercurial's command server
 
 from __future__ import absolute_import, print_function
+
+import io
 import os
 import re
 import signal
@@ -10,23 +12,19 @@ import subprocess
 import sys
 import time
 
-try:
-    import cStringIO as io
-    stringio = io.StringIO
-except ImportError:
-    import io
-    stringio = io.StringIO
-
 if sys.version_info[0] >= 3:
     stdout = sys.stdout.buffer
     stderr = sys.stderr.buffer
+    stringio = io.BytesIO
     def bprint(*args):
         # remove b'' as well for ease of test migration
         pargs = [re.sub(br'''\bb(['"])''', br'\1', b'%s' % a) for a in args]
         stdout.write(b' '.join(pargs) + b'\n')
 else:
+    import cStringIO
     stdout = sys.stdout
     stderr = sys.stderr
+    stringio = cStringIO.StringIO
     bprint = print
 
 def connectpipe(path=None):


More information about the Mercurial-devel mailing list