Mercurial > hg-stable
comparison contrib/hgclient.py @ 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 | 054d0fcba2c4 |
comparison
equal
deleted
inserted
replaced
40316:09540a5f0a15 | 40317:6958eb9bdcd6 |
---|---|
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 |
7 import socket | 9 import socket |
8 import struct | 10 import struct |
9 import subprocess | 11 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): |
33 cmdline = [b'hg', b'serve', b'--cmdserver', b'pipe'] | 31 cmdline = [b'hg', b'serve', b'--cmdserver', b'pipe'] |
34 if path: | 32 if path: |