28 return [args[n] for n in names] |
28 return [args[n] for n in names] |
29 |
29 |
30 def checkperm(self, perm): |
30 def checkperm(self, perm): |
31 pass |
31 pass |
32 |
32 |
|
33 |
33 wireprototypes.TRANSPORTS['dummyproto'] = { |
34 wireprototypes.TRANSPORTS['dummyproto'] = { |
34 'transport': 'dummy', |
35 'transport': 'dummy', |
35 'version': 1, |
36 'version': 1, |
36 } |
37 } |
|
38 |
37 |
39 |
38 class clientpeer(wireprotov1peer.wirepeer): |
40 class clientpeer(wireprotov1peer.wirepeer): |
39 def __init__(self, serverrepo, ui): |
41 def __init__(self, serverrepo, ui): |
40 self.serverrepo = serverrepo |
42 self.serverrepo = serverrepo |
41 self.ui = ui |
43 self.ui = ui |
75 def greet(self, name): |
77 def greet(self, name): |
76 f = wireprotov1peer.future() |
78 f = wireprotov1peer.future() |
77 yield {b'name': mangle(name)}, f |
79 yield {b'name': mangle(name)}, f |
78 yield unmangle(f.value) |
80 yield unmangle(f.value) |
79 |
81 |
|
82 |
80 class serverrepo(object): |
83 class serverrepo(object): |
81 def __init__(self, ui): |
84 def __init__(self, ui): |
82 self.ui = ui |
85 self.ui = ui |
83 |
86 |
84 def greet(self, name): |
87 def greet(self, name): |
85 return b"Hello, " + name |
88 return b"Hello, " + name |
86 |
89 |
87 def filtered(self, name): |
90 def filtered(self, name): |
88 return self |
91 return self |
89 |
92 |
|
93 |
90 def mangle(s): |
94 def mangle(s): |
91 return b''.join(pycompat.bytechr(ord(c) + 1) for c in pycompat.bytestr(s)) |
95 return b''.join(pycompat.bytechr(ord(c) + 1) for c in pycompat.bytestr(s)) |
|
96 |
|
97 |
92 def unmangle(s): |
98 def unmangle(s): |
93 return b''.join(pycompat.bytechr(ord(c) - 1) for c in pycompat.bytestr(s)) |
99 return b''.join(pycompat.bytechr(ord(c) - 1) for c in pycompat.bytestr(s)) |
94 |
100 |
|
101 |
95 def greet(repo, proto, name): |
102 def greet(repo, proto, name): |
96 return mangle(repo.greet(unmangle(name))) |
103 return mangle(repo.greet(unmangle(name))) |
|
104 |
97 |
105 |
98 wireprotov1server.commands[b'greet'] = (greet, b'name') |
106 wireprotov1server.commands[b'greet'] = (greet, b'name') |
99 |
107 |
100 srv = serverrepo(uimod.ui()) |
108 srv = serverrepo(uimod.ui()) |
101 clt = clientpeer(srv, uimod.ui()) |
109 clt = clientpeer(srv, uimod.ui()) |
102 |
110 |
|
111 |
103 def printb(data, end=b'\n'): |
112 def printb(data, end=b'\n'): |
104 out = getattr(sys.stdout, 'buffer', sys.stdout) |
113 out = getattr(sys.stdout, 'buffer', sys.stdout) |
105 out.write(data + end) |
114 out.write(data + end) |
106 out.flush() |
115 out.flush() |
|
116 |
107 |
117 |
108 printb(clt.greet(b"Foobar")) |
118 printb(clt.greet(b"Foobar")) |
109 |
119 |
110 with clt.commandexecutor() as e: |
120 with clt.commandexecutor() as e: |
111 fgreet1 = e.callcommand(b'greet', {b'name': b'Fo, =;:<o'}) |
121 fgreet1 = e.callcommand(b'greet', {b'name': b'Fo, =;:<o'}) |
112 fgreet2 = e.callcommand(b'greet', {b'name': b'Bar'}) |
122 fgreet2 = e.callcommand(b'greet', {b'name': b'Bar'}) |
113 |
123 |
114 printb(stringutil.pprint([f.result() for f in (fgreet1, fgreet2)], |
124 printb( |
115 bprefix=True)) |
125 stringutil.pprint([f.result() for f in (fgreet1, fgreet2)], bprefix=True) |
|
126 ) |