changeset 40317:6958eb9bdcd6

py3: rewrite StringIO fallback for Python 3
author Yuya Nishihara <yuya@tcha.org>
date Tue, 16 Oct 2018 08:06:17 +0200
parents 09540a5f0a15
children 55fd0fefbec4
files contrib/hgclient.py
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/hgclient.py	Tue Oct 16 07:04:07 2018 +0200
+++ b/contrib/hgclient.py	Tue Oct 16 08:06:17 2018 +0200
@@ -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 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):