Mercurial > hg
annotate tests/test-wireproto.py @ 14889:a59058fd074a stable
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
We need to make sure that python hooks I/O goes through the ui descriptors so
it doesn't mess the command server protocol.
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 19:06:59 +0300 |
parents | 08ef6b5f3715 |
children | 1ac628cd7113 |
rev | line source |
---|---|
14622
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
1 from mercurial import wireproto |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
2 |
14764
a7d5816087a9
classes: fix class style problems found by b071cd58af50
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14622
diff
changeset
|
3 class proto(object): |
14622
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
4 def __init__(self, args): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
5 self.args = args |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
6 def getargs(self, spec): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
7 args = self.args |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
8 args.setdefault('*', {}) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
9 names = spec.split() |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
10 return [args[n] for n in names] |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
11 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
12 class clientrepo(wireproto.wirerepository): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
13 def __init__(self, serverrepo): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
14 self.serverrepo = serverrepo |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
15 def _call(self, cmd, **args): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
16 return wireproto.dispatch(self.serverrepo, proto(args), cmd) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
17 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
18 @wireproto.batchable |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
19 def greet(self, name): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
20 f = wireproto.future() |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
21 yield wireproto.todict(name=mangle(name)), f |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
22 yield unmangle(f.value) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
23 |
14764
a7d5816087a9
classes: fix class style problems found by b071cd58af50
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14622
diff
changeset
|
24 class serverrepo(object): |
14622
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
25 def greet(self, name): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
26 return "Hello, " + name |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
27 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
28 def mangle(s): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
29 return ''.join(chr(ord(c) + 1) for c in s) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
30 def unmangle(s): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
31 return ''.join(chr(ord(c) - 1) for c in s) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
32 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
33 def greet(repo, proto, name): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
34 return mangle(repo.greet(unmangle(name))) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
35 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
36 wireproto.commands['greet'] = (greet, 'name',) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
37 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
38 srv = serverrepo() |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
39 clt = clientrepo(srv) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
40 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
41 print clt.greet("Foobar") |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
42 b = clt.batch() |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
43 fs = [b.greet(s) for s in ["Fo, =;o", "Bar"]] |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
44 b.submit() |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff
changeset
|
45 print [f.value for f in fs] |