##// END OF EJS Templates
wireproto: rename wireproto to wireprotov1server (API)...
Gregory Szorc -
r37803:b4d85bc1 default
parent child Browse files
Show More
@@ -198,7 +198,7 b' from __future__ import absolute_import'
198
198
199 from mercurial import (
199 from mercurial import (
200 extensions,
200 extensions,
201 wireproto,
201 wireprotov1server,
202 )
202 )
203
203
204 testedwith = 'ships-with-hg-core'
204 testedwith = 'ships-with-hg-core'
@@ -215,4 +215,4 b' def capabilities(orig, repo, proto):'
215 return caps
215 return caps
216
216
217 def extsetup(ui):
217 def extsetup(ui):
218 extensions.wrapfunction(wireproto, '_capabilities', capabilities)
218 extensions.wrapfunction(wireprotov1server, '_capabilities', capabilities)
@@ -125,9 +125,9 b' from mercurial import ('
125 pycompat,
125 pycompat,
126 registrar,
126 registrar,
127 util,
127 util,
128 wireproto,
129 wireprototypes,
128 wireprototypes,
130 wireprotov1peer,
129 wireprotov1peer,
130 wireprotov1server,
131 )
131 )
132
132
133 from . import (
133 from . import (
@@ -278,7 +278,7 b' def extsetup(ui):'
278 clientextsetup(ui)
278 clientextsetup(ui)
279
279
280 def commonsetup(ui):
280 def commonsetup(ui):
281 wireproto.commands['listkeyspatterns'] = (
281 wireprotov1server.commands['listkeyspatterns'] = (
282 wireprotolistkeyspatterns, 'namespace patterns')
282 wireprotolistkeyspatterns, 'namespace patterns')
283 scratchbranchpat = ui.config('infinitepush', 'branchpattern')
283 scratchbranchpat = ui.config('infinitepush', 'branchpattern')
284 if scratchbranchpat:
284 if scratchbranchpat:
@@ -302,8 +302,8 b' def serverextsetup(ui):'
302
302
303 extensions.wrapfunction(localrepo.localrepository, 'listkeys',
303 extensions.wrapfunction(localrepo.localrepository, 'listkeys',
304 localrepolistkeys)
304 localrepolistkeys)
305 wireproto.commands['lookup'] = (
305 wireprotov1server.commands['lookup'] = (
306 _lookupwrap(wireproto.commands['lookup'][0]), 'key')
306 _lookupwrap(wireprotov1server.commands['lookup'][0]), 'key')
307 extensions.wrapfunction(exchange, 'getbundlechunks', getbundlechunks)
307 extensions.wrapfunction(exchange, 'getbundlechunks', getbundlechunks)
308
308
309 extensions.wrapfunction(bundle2, 'processparts', processparts)
309 extensions.wrapfunction(bundle2, 'processparts', processparts)
@@ -31,7 +31,7 b' from mercurial import ('
31 subrepo,
31 subrepo,
32 upgrade,
32 upgrade,
33 url,
33 url,
34 wireproto,
34 wireprotov1server,
35 )
35 )
36
36
37 from . import (
37 from . import (
@@ -164,22 +164,24 b' def uisetup(ui):'
164 overrides.openlargefile)
164 overrides.openlargefile)
165
165
166 # create the new wireproto commands ...
166 # create the new wireproto commands ...
167 wireproto.wireprotocommand('putlfile', 'sha', permission='push')(
167 wireprotov1server.wireprotocommand('putlfile', 'sha', permission='push')(
168 proto.putlfile)
168 proto.putlfile)
169 wireproto.wireprotocommand('getlfile', 'sha', permission='pull')(
169 wireprotov1server.wireprotocommand('getlfile', 'sha', permission='pull')(
170 proto.getlfile)
170 proto.getlfile)
171 wireproto.wireprotocommand('statlfile', 'sha', permission='pull')(
171 wireprotov1server.wireprotocommand('statlfile', 'sha', permission='pull')(
172 proto.statlfile)
172 proto.statlfile)
173 wireproto.wireprotocommand('lheads', '', permission='pull')(
173 wireprotov1server.wireprotocommand('lheads', '', permission='pull')(
174 wireproto.heads)
174 wireprotov1server.heads)
175
175
176 # ... and wrap some existing ones
176 # ... and wrap some existing ones
177 extensions.wrapfunction(wireproto.commands['heads'], 'func', proto.heads)
177 extensions.wrapfunction(wireprotov1server.commands['heads'], 'func',
178 proto.heads)
178 # TODO also wrap wireproto.commandsv2 once heads is implemented there.
179 # TODO also wrap wireproto.commandsv2 once heads is implemented there.
179
180
180 extensions.wrapfunction(webcommands, 'decodepath', overrides.decodepath)
181 extensions.wrapfunction(webcommands, 'decodepath', overrides.decodepath)
181
182
182 extensions.wrapfunction(wireproto, '_capabilities', proto._capabilities)
183 extensions.wrapfunction(wireprotov1server, '_capabilities',
184 proto._capabilities)
183
185
184 # can't do this in reposetup because it needs to have happened before
186 # can't do this in reposetup because it needs to have happened before
185 # wirerepo.__init__ is called
187 # wirerepo.__init__ is called
@@ -149,8 +149,8 b' from mercurial import ('
149 upgrade,
149 upgrade,
150 util,
150 util,
151 vfs as vfsmod,
151 vfs as vfsmod,
152 wireproto,
153 wireprotoserver,
152 wireprotoserver,
153 wireprotov1server,
154 )
154 )
155
155
156 from . import (
156 from . import (
@@ -323,7 +323,7 b' def extsetup(ui):'
323 wrapper.allsupportedversions)
323 wrapper.allsupportedversions)
324
324
325 wrapfunction(exchange, 'push', wrapper.push)
325 wrapfunction(exchange, 'push', wrapper.push)
326 wrapfunction(wireproto, '_capabilities', wrapper._capabilities)
326 wrapfunction(wireprotov1server, '_capabilities', wrapper._capabilities)
327 wrapfunction(wireprotoserver, 'handlewsgirequest',
327 wrapfunction(wireprotoserver, 'handlewsgirequest',
328 wireprotolfsserver.handlewsgirequest)
328 wireprotolfsserver.handlewsgirequest)
329
329
@@ -15,10 +15,10 b' from . import ('
15 error,
15 error,
16 pycompat,
16 pycompat,
17 util,
17 util,
18 wireproto,
19 wireprotoserver,
18 wireprotoserver,
20 wireprototypes,
19 wireprototypes,
21 wireprotov1peer,
20 wireprotov1peer,
21 wireprotov1server,
22 )
22 )
23 from .utils import (
23 from .utils import (
24 procutil,
24 procutil,
@@ -441,7 +441,7 b' class sshv1peer(wireprotov1peer.wirepeer'
441 dbg(line % ' %s-%s: %d' % (key, dk, len(dv)))
441 dbg(line % ' %s-%s: %d' % (key, dk, len(dv)))
442 self.ui.debug("sending %s command\n" % cmd)
442 self.ui.debug("sending %s command\n" % cmd)
443 self._pipeo.write("%s\n" % cmd)
443 self._pipeo.write("%s\n" % cmd)
444 _func, names = wireproto.commands[cmd]
444 _func, names = wireprotov1server.commands[cmd]
445 keys = names.split()
445 keys = names.split()
446 wireargs = {}
446 wireargs = {}
447 for k in keys:
447 for k in keys:
@@ -24,8 +24,8 b' from . import ('
24 hook,
24 hook,
25 pycompat,
25 pycompat,
26 util,
26 util,
27 wireproto,
28 wireprototypes,
27 wireprototypes,
28 wireprotov1server,
29 wireprotov2server,
29 wireprotov2server,
30 )
30 )
31 from .utils import (
31 from .utils import (
@@ -166,7 +166,7 b' class httpv1protocolhandler(object):'
166 # there are no other known users, so with any luck we can discard this
166 # there are no other known users, so with any luck we can discard this
167 # hook if remotefilelog becomes a first-party extension.
167 # hook if remotefilelog becomes a first-party extension.
168 def iscmd(cmd):
168 def iscmd(cmd):
169 return cmd in wireproto.commands
169 return cmd in wireprotov1server.commands
170
170
171 def handlewsgirequest(rctx, req, res, checkperm):
171 def handlewsgirequest(rctx, req, res, checkperm):
172 """Possibly process a wire protocol request.
172 """Possibly process a wire protocol request.
@@ -329,7 +329,7 b' def _httpresponsetype(ui, proto, prefer_'
329 return HGTYPE2, util._noopengine(), {}
329 return HGTYPE2, util._noopengine(), {}
330
330
331 # Now find an agreed upon compression format.
331 # Now find an agreed upon compression format.
332 compformats = wireproto.clientcompressionsupport(proto)
332 compformats = wireprotov1server.clientcompressionsupport(proto)
333 for engine in wireprototypes.supportedcompengines(ui, util.SERVERROLE):
333 for engine in wireprototypes.supportedcompengines(ui, util.SERVERROLE):
334 if engine.wireprotosupport().name in compformats:
334 if engine.wireprotosupport().name in compformats:
335 opts = {}
335 opts = {}
@@ -380,7 +380,7 b' def processcapabilitieshandshake(repo, r'
380
380
381 descriptors[api] = descriptorfn(req, repo)
381 descriptors[api] = descriptorfn(req, repo)
382
382
383 v1caps = wireproto.dispatch(repo, proto, 'capabilities')
383 v1caps = wireprotov1server.dispatch(repo, proto, 'capabilities')
384 assert isinstance(v1caps, wireprototypes.bytesresponse)
384 assert isinstance(v1caps, wireprototypes.bytesresponse)
385
385
386 m = {
386 m = {
@@ -424,13 +424,13 b' def _callhttp(repo, req, res, proto, cmd'
424 if bodygen is not None:
424 if bodygen is not None:
425 res.setbodygen(bodygen)
425 res.setbodygen(bodygen)
426
426
427 if not wireproto.commands.commandavailable(cmd, proto):
427 if not wireprotov1server.commands.commandavailable(cmd, proto):
428 setresponse(HTTP_OK, HGERRTYPE,
428 setresponse(HTTP_OK, HGERRTYPE,
429 _('requested wire protocol command is not available over '
429 _('requested wire protocol command is not available over '
430 'HTTP'))
430 'HTTP'))
431 return
431 return
432
432
433 proto.checkperm(wireproto.commands[cmd].permission)
433 proto.checkperm(wireprotov1server.commands[cmd].permission)
434
434
435 # Possibly handle a modern client wanting to switch protocols.
435 # Possibly handle a modern client wanting to switch protocols.
436 if (cmd == 'capabilities' and
436 if (cmd == 'capabilities' and
@@ -438,7 +438,7 b' def _callhttp(repo, req, res, proto, cmd'
438
438
439 return
439 return
440
440
441 rsp = wireproto.dispatch(repo, proto, cmd)
441 rsp = wireprotov1server.dispatch(repo, proto, cmd)
442
442
443 if isinstance(rsp, bytes):
443 if isinstance(rsp, bytes):
444 setresponse(HTTP_OK, HGTYPE, bodybytes=rsp)
444 setresponse(HTTP_OK, HGTYPE, bodybytes=rsp)
@@ -649,7 +649,8 b' def _runsshserver(ui, repo, fin, fout, e'
649 state = 'upgrade-initial'
649 state = 'upgrade-initial'
650 continue
650 continue
651
651
652 available = wireproto.commands.commandavailable(request, proto)
652 available = wireprotov1server.commands.commandavailable(
653 request, proto)
653
654
654 # This command isn't available. Send an empty response and go
655 # This command isn't available. Send an empty response and go
655 # back to waiting for a new command.
656 # back to waiting for a new command.
@@ -657,7 +658,7 b' def _runsshserver(ui, repo, fin, fout, e'
657 _sshv1respondbytes(fout, b'')
658 _sshv1respondbytes(fout, b'')
658 continue
659 continue
659
660
660 rsp = wireproto.dispatch(repo, proto, request)
661 rsp = wireprotov1server.dispatch(repo, proto, request)
661
662
662 if isinstance(rsp, bytes):
663 if isinstance(rsp, bytes):
663 _sshv1respondbytes(fout, rsp)
664 _sshv1respondbytes(fout, rsp)
@@ -764,7 +765,7 b' def _runsshserver(ui, repo, fin, fout, e'
764 elif state == 'upgrade-v2-finish':
765 elif state == 'upgrade-v2-finish':
765 # Send the upgrade response.
766 # Send the upgrade response.
766 fout.write(b'upgraded %s %s\n' % (token, SSHV2))
767 fout.write(b'upgraded %s %s\n' % (token, SSHV2))
767 servercaps = wireproto.capabilities(repo, proto)
768 servercaps = wireprotov1server.capabilities(repo, proto)
768 rsp = b'capabilities: %s' % servercaps.data
769 rsp = b'capabilities: %s' % servercaps.data
769 fout.write(b'%d\n%s\n' % (len(rsp), rsp))
770 fout.write(b'%d\n%s\n' % (len(rsp), rsp))
770 fout.flush()
771 fout.flush()
@@ -1,4 +1,4 b''
1 # wireproto.py - generic wire protocol support functions
1 # wireprotov1server.py - Wire protocol version 1 server functionality
2 #
2 #
3 # Copyright 2005-2010 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2010 Matt Mackall <mpm@selenic.com>
4 #
4 #
@@ -15,8 +15,8 b' from mercurial import ('
15 extensions,
15 extensions,
16 registrar,
16 registrar,
17 sshpeer,
17 sshpeer,
18 wireproto,
19 wireprotoserver,
18 wireprotoserver,
19 wireprotov1server,
20 )
20 )
21
21
22 configtable = {}
22 configtable = {}
@@ -50,7 +50,7 b' class prehelloserver(wireprotoserver.ssh'
50 assert l == b'between\n'
50 assert l == b'between\n'
51 proto = wireprotoserver.sshv1protocolhandler(self._ui, self._fin,
51 proto = wireprotoserver.sshv1protocolhandler(self._ui, self._fin,
52 self._fout)
52 self._fout)
53 rsp = wireproto.dispatch(self._repo, proto, b'between')
53 rsp = wireprotov1server.dispatch(self._repo, proto, b'between')
54 wireprotoserver._sshv1respondbytes(self._fout, rsp.data)
54 wireprotoserver._sshv1respondbytes(self._fout, rsp.data)
55
55
56 super(prehelloserver, self).serve_forever()
56 super(prehelloserver, self).serve_forever()
@@ -3,7 +3,7 b''
3 $ cat > fakeremoteuser.py << EOF
3 $ cat > fakeremoteuser.py << EOF
4 > import os
4 > import os
5 > from mercurial.hgweb import hgweb_mod
5 > from mercurial.hgweb import hgweb_mod
6 > from mercurial import wireproto
6 > from mercurial import wireprotov1server
7 > class testenvhgweb(hgweb_mod.hgweb):
7 > class testenvhgweb(hgweb_mod.hgweb):
8 > def __call__(self, env, respond):
8 > def __call__(self, env, respond):
9 > # Allow REMOTE_USER to define authenticated user.
9 > # Allow REMOTE_USER to define authenticated user.
@@ -15,16 +15,16 b''
15 > return super(testenvhgweb, self).__call__(env, respond)
15 > return super(testenvhgweb, self).__call__(env, respond)
16 > hgweb_mod.hgweb = testenvhgweb
16 > hgweb_mod.hgweb = testenvhgweb
17 >
17 >
18 > @wireproto.wireprotocommand('customreadnoperm')
18 > @wireprotov1server.wireprotocommand('customreadnoperm')
19 > def customread(repo, proto):
19 > def customread(repo, proto):
20 > return b'read-only command no defined permissions\n'
20 > return b'read-only command no defined permissions\n'
21 > @wireproto.wireprotocommand('customwritenoperm')
21 > @wireprotov1server.wireprotocommand('customwritenoperm')
22 > def customwritenoperm(repo, proto):
22 > def customwritenoperm(repo, proto):
23 > return b'write command no defined permissions\n'
23 > return b'write command no defined permissions\n'
24 > @wireproto.wireprotocommand('customreadwithperm', permission='pull')
24 > @wireprotov1server.wireprotocommand('customreadwithperm', permission='pull')
25 > def customreadwithperm(repo, proto):
25 > def customreadwithperm(repo, proto):
26 > return b'read-only command w/ defined permissions\n'
26 > return b'read-only command w/ defined permissions\n'
27 > @wireproto.wireprotocommand('customwritewithperm', permission='push')
27 > @wireprotov1server.wireprotocommand('customwritewithperm', permission='push')
28 > def customwritewithperm(repo, proto):
28 > def customwritewithperm(repo, proto):
29 > return b'write command w/ defined permissions\n'
29 > return b'write command w/ defined permissions\n'
30 > EOF
30 > EOF
@@ -6,8 +6,8 b' import unittest'
6 import silenttestrunner
6 import silenttestrunner
7
7
8 from mercurial import (
8 from mercurial import (
9 wireproto,
10 wireprotoserver,
9 wireprotoserver,
10 wireprotov1server,
11 )
11 )
12
12
13 from mercurial.utils import (
13 from mercurial.utils import (
@@ -29,7 +29,7 b' class SSHServerGetArgsTests(unittest.Tes'
29 proto = wireprotoserver.sshv1protocolhandler(server._ui,
29 proto = wireprotoserver.sshv1protocolhandler(server._ui,
30 server._fin,
30 server._fin,
31 server._fout)
31 server._fout)
32 _func, spec = wireproto.commands[cmd]
32 _func, spec = wireprotov1server.commands[cmd]
33 self.assertEqual(proto.getargs(spec), expected)
33 self.assertEqual(proto.getargs(spec), expected)
34
34
35 def mockserver(inbytes):
35 def mockserver(inbytes):
@@ -5,9 +5,9 b' from mercurial import ('
5 pycompat,
5 pycompat,
6 ui as uimod,
6 ui as uimod,
7 util,
7 util,
8 wireproto,
9 wireprototypes,
8 wireprototypes,
10 wireprotov1peer,
9 wireprotov1peer,
10 wireprotov1server,
11 )
11 )
12 stringio = util.stringio
12 stringio = util.stringio
13
13
@@ -55,7 +55,7 b' class clientpeer(wireprotov1peer.wirepee'
55
55
56 def _call(self, cmd, **args):
56 def _call(self, cmd, **args):
57 args = pycompat.byteskwargs(args)
57 args = pycompat.byteskwargs(args)
58 res = wireproto.dispatch(self.serverrepo, proto(args), cmd)
58 res = wireprotov1server.dispatch(self.serverrepo, proto(args), cmd)
59 if isinstance(res, wireprototypes.bytesresponse):
59 if isinstance(res, wireprototypes.bytesresponse):
60 return res.data
60 return res.data
61 elif isinstance(res, bytes):
61 elif isinstance(res, bytes):
@@ -87,7 +87,7 b' def unmangle(s):'
87 def greet(repo, proto, name):
87 def greet(repo, proto, name):
88 return mangle(repo.greet(unmangle(name)))
88 return mangle(repo.greet(unmangle(name)))
89
89
90 wireproto.commands[b'greet'] = (greet, b'name',)
90 wireprotov1server.commands[b'greet'] = (greet, b'name')
91
91
92 srv = serverrepo()
92 srv = serverrepo()
93 clt = clientpeer(srv, uimod.ui())
93 clt = clientpeer(srv, uimod.ui())
@@ -16,11 +16,11 b' sendhttpv2peerhandshake() {'
16 cat > dummycommands.py << EOF
16 cat > dummycommands.py << EOF
17 from mercurial import (
17 from mercurial import (
18 wireprototypes,
18 wireprototypes,
19 wireprotov1server,
19 wireprotov2server,
20 wireprotov2server,
20 wireproto,
21 )
21 )
22
22
23 @wireproto.wireprotocommand('customreadonly', permission='pull')
23 @wireprotov1server.wireprotocommand('customreadonly', permission='pull')
24 def customreadonlyv1(repo, proto):
24 def customreadonlyv1(repo, proto):
25 return wireprototypes.bytesresponse(b'customreadonly bytes response')
25 return wireprototypes.bytesresponse(b'customreadonly bytes response')
26
26
@@ -28,7 +28,7 b' def customreadonlyv1(repo, proto):'
28 def customreadonlyv2(repo, proto):
28 def customreadonlyv2(repo, proto):
29 return wireprototypes.cborresponse(b'customreadonly bytes response')
29 return wireprototypes.cborresponse(b'customreadonly bytes response')
30
30
31 @wireproto.wireprotocommand('customreadwrite', permission='push')
31 @wireprotov1server.wireprotocommand('customreadwrite', permission='push')
32 def customreadwrite(repo, proto):
32 def customreadwrite(repo, proto):
33 return wireprototypes.bytesresponse(b'customreadwrite bytes response')
33 return wireprototypes.bytesresponse(b'customreadwrite bytes response')
34
34
General Comments 0
You need to be logged in to leave comments. Login now