##// END OF EJS Templates
py3: rewrite StringIO fallback for Python 3
Yuya Nishihara -
r40353:6958eb9b default
parent child Browse files
Show More
@@ -1,6 +1,8 b''
1 # A minimal client for Mercurial's command server
1 # A minimal client for Mercurial's command server
2
2
3 from __future__ import absolute_import, print_function
3 from __future__ import absolute_import, print_function
4
5 import io
4 import os
6 import os
5 import re
7 import re
6 import signal
8 import signal
@@ -10,23 +12,19 b' import subprocess'
10 import sys
12 import sys
11 import time
13 import time
12
14
13 try:
14 import cStringIO as io
15 stringio = io.StringIO
16 except ImportError:
17 import io
18 stringio = io.StringIO
19
20 if sys.version_info[0] >= 3:
15 if sys.version_info[0] >= 3:
21 stdout = sys.stdout.buffer
16 stdout = sys.stdout.buffer
22 stderr = sys.stderr.buffer
17 stderr = sys.stderr.buffer
18 stringio = io.BytesIO
23 def bprint(*args):
19 def bprint(*args):
24 # remove b'' as well for ease of test migration
20 # remove b'' as well for ease of test migration
25 pargs = [re.sub(br'''\bb(['"])''', br'\1', b'%s' % a) for a in args]
21 pargs = [re.sub(br'''\bb(['"])''', br'\1', b'%s' % a) for a in args]
26 stdout.write(b' '.join(pargs) + b'\n')
22 stdout.write(b' '.join(pargs) + b'\n')
27 else:
23 else:
24 import cStringIO
28 stdout = sys.stdout
25 stdout = sys.stdout
29 stderr = sys.stderr
26 stderr = sys.stderr
27 stringio = cStringIO.StringIO
30 bprint = print
28 bprint = print
31
29
32 def connectpipe(path=None):
30 def connectpipe(path=None):
General Comments 0
You need to be logged in to leave comments. Login now