Mercurial > hg-stable
annotate contrib/hgclient.py @ 40316:09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 16 Oct 2018 07:04:07 +0200 |
parents | 431a831342d2 |
children | 6958eb9bdcd6 |
rev | line source |
---|---|
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
1 # A minimal client for Mercurial's command server |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
2 |
28355
897a4bbd578b
hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
22993
diff
changeset
|
3 from __future__ import absolute_import, print_function |
897a4bbd578b
hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
22993
diff
changeset
|
4 import os |
40316
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
5 import re |
28355
897a4bbd578b
hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
22993
diff
changeset
|
6 import signal |
897a4bbd578b
hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
22993
diff
changeset
|
7 import socket |
897a4bbd578b
hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
22993
diff
changeset
|
8 import struct |
897a4bbd578b
hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
22993
diff
changeset
|
9 import subprocess |
897a4bbd578b
hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
22993
diff
changeset
|
10 import sys |
897a4bbd578b
hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
22993
diff
changeset
|
11 import time |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
12 |
28836
3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents:
28355
diff
changeset
|
13 try: |
3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents:
28355
diff
changeset
|
14 import cStringIO as io |
3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents:
28355
diff
changeset
|
15 stringio = io.StringIO |
3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents:
28355
diff
changeset
|
16 except ImportError: |
3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents:
28355
diff
changeset
|
17 import io |
3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents:
28355
diff
changeset
|
18 stringio = io.StringIO |
3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents:
28355
diff
changeset
|
19 |
40315
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
20 if sys.version_info[0] >= 3: |
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
21 stdout = sys.stdout.buffer |
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
22 stderr = sys.stderr.buffer |
40316
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
23 def bprint(*args): |
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
24 # remove b'' as well for ease of test migration |
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
25 pargs = [re.sub(br'''\bb(['"])''', br'\1', b'%s' % a) for a in args] |
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
26 stdout.write(b' '.join(pargs) + b'\n') |
40315
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
27 else: |
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
28 stdout = sys.stdout |
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
29 stderr = sys.stderr |
40316
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
30 bprint = print |
40315
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
31 |
22992
892b2b8c1b50
test-commandserver: allow check() to make connection in different way
Yuya Nishihara <yuya@tcha.org>
parents:
22991
diff
changeset
|
32 def connectpipe(path=None): |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
33 cmdline = [b'hg', b'serve', b'--cmdserver', b'pipe'] |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
34 if path: |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
35 cmdline += [b'-R', path] |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
36 |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
37 server = subprocess.Popen(cmdline, stdin=subprocess.PIPE, |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
38 stdout=subprocess.PIPE) |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
39 |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
40 return server |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
41 |
22993
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
42 class unixconnection(object): |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
43 def __init__(self, sockpath): |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
44 self.sock = sock = socket.socket(socket.AF_UNIX) |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
45 sock.connect(sockpath) |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
46 self.stdin = sock.makefile('wb') |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
47 self.stdout = sock.makefile('rb') |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
48 |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
49 def wait(self): |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
50 self.stdin.close() |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
51 self.stdout.close() |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
52 self.sock.close() |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
53 |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
54 class unixserver(object): |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
55 def __init__(self, sockpath, logpath=None, repopath=None): |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
56 self.sockpath = sockpath |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
57 cmdline = [b'hg', b'serve', b'--cmdserver', b'unix', b'-a', sockpath] |
22993
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
58 if repopath: |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
59 cmdline += [b'-R', repopath] |
22993
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
60 if logpath: |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
61 stdout = open(logpath, 'a') |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
62 stderr = subprocess.STDOUT |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
63 else: |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
64 stdout = stderr = None |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
65 self.server = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr) |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
66 # wait for listen() |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
67 while self.server.poll() is None: |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
68 if os.path.exists(sockpath): |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
69 break |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
70 time.sleep(0.1) |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
71 |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
72 def connect(self): |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
73 return unixconnection(self.sockpath) |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
74 |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
75 def shutdown(self): |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
76 os.kill(self.server.pid, signal.SIGTERM) |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
77 self.server.wait() |
24c5fd2894f8
test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents:
22992
diff
changeset
|
78 |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
79 def writeblock(server, data): |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
80 server.stdin.write(struct.pack(b'>I', len(data))) |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
81 server.stdin.write(data) |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
82 server.stdin.flush() |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
83 |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
84 def readchannel(server): |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
85 data = server.stdout.read(5) |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
86 if not data: |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
87 raise EOFError |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
88 channel, length = struct.unpack('>cI', data) |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
89 if channel in b'IL': |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
90 return channel, length |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
91 else: |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
92 return channel, server.stdout.read(length) |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
93 |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
94 def sep(text): |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
95 return text.replace(b'\\', b'/') |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
96 |
40315
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
97 def runcommand(server, args, output=stdout, error=stderr, input=None, |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
98 outfilter=lambda x: x): |
40316
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
99 bprint(b'*** runcommand', b' '.join(args)) |
40315
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
100 stdout.flush() |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
101 server.stdin.write(b'runcommand\n') |
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
102 writeblock(server, b'\0'.join(args)) |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
103 |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
104 if not input: |
28836
3f45488d70df
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents:
28355
diff
changeset
|
105 input = stringio() |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
106 |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
107 while True: |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
108 ch, data = readchannel(server) |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
109 if ch == b'o': |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
110 output.write(outfilter(data)) |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
111 output.flush() |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
112 elif ch == b'e': |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
113 error.write(data) |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
114 error.flush() |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
115 elif ch == b'I': |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
116 writeblock(server, input.read(data)) |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
117 elif ch == b'L': |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
118 writeblock(server, input.readline(data)) |
40314
73c2b9c9cd3c
py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
28836
diff
changeset
|
119 elif ch == b'r': |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
120 ret, = struct.unpack('>i', data) |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
121 if ret != 0: |
40316
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
122 bprint(b' [%d]' % ret) |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
123 return ret |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
124 else: |
40316
09540a5f0a15
py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40315
diff
changeset
|
125 bprint(b"unexpected channel %c: %r" % (ch, data)) |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
126 if ch.isupper(): |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
127 return |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
128 |
22992
892b2b8c1b50
test-commandserver: allow check() to make connection in different way
Yuya Nishihara <yuya@tcha.org>
parents:
22991
diff
changeset
|
129 def check(func, connect=connectpipe): |
40315
431a831342d2
py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents:
40314
diff
changeset
|
130 stdout.flush() |
22991
a94594f5d52f
test-commandserver: remove unused repopath argument from check()
Yuya Nishihara <yuya@tcha.org>
parents:
22572
diff
changeset
|
131 server = connect() |
22566
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
132 try: |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
133 return func(server) |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
134 finally: |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
135 server.stdin.close() |
480b7fefbb08
test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
136 server.wait() |