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

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 16, 2018, 7:26 a.m.
Message ID <a202f1b4611205a08a67.1539674803@mimosa>
Download mbox | patch
Permalink /patch/36027/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 16, 2018, 7:26 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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

Patch

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):