Mercurial > hg
comparison tests/test-wireproto.py @ 14765:08ef6b5f3715 stable
test-wireprotocol.py: rename to test-wireproto.py for consistency
1. The module named 'wireproto' is tested.
2. There already is a test-wireproto.t for related tests on shell level.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Wed, 29 Jun 2011 13:04:00 +0200 |
parents | tests/test-wireprotocol.py@a7d5816087a9 |
children | 1ac628cd7113 |
comparison
equal
deleted
inserted
replaced
14764:a7d5816087a9 | 14765:08ef6b5f3715 |
---|---|
1 from mercurial import wireproto | |
2 | |
3 class proto(object): | |
4 def __init__(self, args): | |
5 self.args = args | |
6 def getargs(self, spec): | |
7 args = self.args | |
8 args.setdefault('*', {}) | |
9 names = spec.split() | |
10 return [args[n] for n in names] | |
11 | |
12 class clientrepo(wireproto.wirerepository): | |
13 def __init__(self, serverrepo): | |
14 self.serverrepo = serverrepo | |
15 def _call(self, cmd, **args): | |
16 return wireproto.dispatch(self.serverrepo, proto(args), cmd) | |
17 | |
18 @wireproto.batchable | |
19 def greet(self, name): | |
20 f = wireproto.future() | |
21 yield wireproto.todict(name=mangle(name)), f | |
22 yield unmangle(f.value) | |
23 | |
24 class serverrepo(object): | |
25 def greet(self, name): | |
26 return "Hello, " + name | |
27 | |
28 def mangle(s): | |
29 return ''.join(chr(ord(c) + 1) for c in s) | |
30 def unmangle(s): | |
31 return ''.join(chr(ord(c) - 1) for c in s) | |
32 | |
33 def greet(repo, proto, name): | |
34 return mangle(repo.greet(unmangle(name))) | |
35 | |
36 wireproto.commands['greet'] = (greet, 'name',) | |
37 | |
38 srv = serverrepo() | |
39 clt = clientrepo(srv) | |
40 | |
41 print clt.greet("Foobar") | |
42 b = clt.batch() | |
43 fs = [b.greet(s) for s in ["Fo, =;o", "Bar"]] | |
44 b.submit() | |
45 print [f.value for f in fs] |