comparison tests/test-wireproto.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents d6569f1e9b37
children c424ff4807e6
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
9 util, 9 util,
10 wireprototypes, 10 wireprototypes,
11 wireprotov1peer, 11 wireprotov1peer,
12 wireprotov1server, 12 wireprotov1server,
13 ) 13 )
14 from mercurial.utils import ( 14 from mercurial.utils import stringutil
15 stringutil, 15
16 )
17 stringio = util.stringio 16 stringio = util.stringio
17
18 18
19 class proto(object): 19 class proto(object):
20 def __init__(self, args): 20 def __init__(self, args):
21 self.args = args 21 self.args = args
22 self.name = 'dummyproto' 22 self.name = 'dummyproto'
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 )