##// END OF EJS Templates
wireproto: move version 2 commands dict to wireprotov2server...
Gregory Szorc -
r37802:ee0d5e9d default
parent child Browse files
Show More
@@ -114,12 +114,8 b' def bundle1allowed(repo, action):'
114
114
115 return ui.configbool('server', 'bundle1')
115 return ui.configbool('server', 'bundle1')
116
116
117 # For version 1 transports.
118 commands = wireprototypes.commanddict()
117 commands = wireprototypes.commanddict()
119
118
120 # For version 2 transports.
121 commandsv2 = wireprototypes.commanddict()
122
123 def wireprotocommand(name, args=None, permission='push'):
119 def wireprotocommand(name, args=None, permission='push'):
124 """Decorator to declare a wire protocol command.
120 """Decorator to declare a wire protocol command.
125
121
@@ -21,7 +21,6 b' from . import ('
21 pycompat,
21 pycompat,
22 streamclone,
22 streamclone,
23 util,
23 util,
24 wireproto,
25 wireprotoframing,
24 wireprotoframing,
26 wireprototypes,
25 wireprototypes,
27 )
26 )
@@ -30,6 +29,8 b" FRAMINGTYPE = b'application/mercurial-ex"
30
29
31 HTTP_WIREPROTO_V2 = wireprototypes.HTTP_WIREPROTO_V2
30 HTTP_WIREPROTO_V2 = wireprototypes.HTTP_WIREPROTO_V2
32
31
32 COMMANDS = wireprototypes.commanddict()
33
33 def handlehttpv2request(rctx, req, res, checkperm, urlparts):
34 def handlehttpv2request(rctx, req, res, checkperm, urlparts):
34 from .hgweb import common as hgwebcommon
35 from .hgweb import common as hgwebcommon
35
36
@@ -87,7 +88,7 b' def handlehttpv2request(rctx, req, res, '
87 # extension.
88 # extension.
88 extracommands = {'multirequest'}
89 extracommands = {'multirequest'}
89
90
90 if command not in wireproto.commandsv2 and command not in extracommands:
91 if command not in COMMANDS and command not in extracommands:
91 res.status = b'404 Not Found'
92 res.status = b'404 Not Found'
92 res.headers[b'Content-Type'] = b'text/plain'
93 res.headers[b'Content-Type'] = b'text/plain'
93 res.setbodybytes(_('unknown wire protocol command: %s\n') % command)
94 res.setbodybytes(_('unknown wire protocol command: %s\n') % command)
@@ -98,7 +99,7 b' def handlehttpv2request(rctx, req, res, '
98
99
99 proto = httpv2protocolhandler(req, ui)
100 proto = httpv2protocolhandler(req, ui)
100
101
101 if (not wireproto.commandsv2.commandavailable(command, proto)
102 if (not COMMANDS.commandavailable(command, proto)
102 and command not in extracommands):
103 and command not in extracommands):
103 res.status = b'404 Not Found'
104 res.status = b'404 Not Found'
104 res.headers[b'Content-Type'] = b'text/plain'
105 res.headers[b'Content-Type'] = b'text/plain'
@@ -254,7 +255,7 b' def _httpv2runcommand(ui, repo, req, res'
254 proto = httpv2protocolhandler(req, ui, args=command['args'])
255 proto = httpv2protocolhandler(req, ui, args=command['args'])
255
256
256 if reqcommand == b'multirequest':
257 if reqcommand == b'multirequest':
257 if not wireproto.commandsv2.commandavailable(command['command'], proto):
258 if not COMMANDS.commandavailable(command['command'], proto):
258 # TODO proper error mechanism
259 # TODO proper error mechanism
259 res.status = b'200 OK'
260 res.status = b'200 OK'
260 res.headers[b'Content-Type'] = b'text/plain'
261 res.headers[b'Content-Type'] = b'text/plain'
@@ -264,7 +265,7 b' def _httpv2runcommand(ui, repo, req, res'
264
265
265 # TODO don't use assert here, since it may be elided by -O.
266 # TODO don't use assert here, since it may be elided by -O.
266 assert authedperm in (b'ro', b'rw')
267 assert authedperm in (b'ro', b'rw')
267 wirecommand = wireproto.commandsv2[command['command']]
268 wirecommand = COMMANDS[command['command']]
268 assert wirecommand.permission in ('push', 'pull')
269 assert wirecommand.permission in ('push', 'pull')
269
270
270 if authedperm == b'ro' and wirecommand.permission != 'pull':
271 if authedperm == b'ro' and wirecommand.permission != 'pull':
@@ -334,7 +335,7 b' def getdispatchrepo(repo, proto, command'
334 def dispatch(repo, proto, command):
335 def dispatch(repo, proto, command):
335 repo = getdispatchrepo(repo, proto, command)
336 repo = getdispatchrepo(repo, proto, command)
336
337
337 func, spec = wireproto.commandsv2[command]
338 func, spec = COMMANDS[command]
338 args = proto.getargs(spec)
339 args = proto.getargs(spec)
339
340
340 return func(repo, proto, **args)
341 return func(repo, proto, **args)
@@ -404,7 +405,7 b' def _capabilitiesv2(repo, proto):'
404 'framingmediatypes': [FRAMINGTYPE],
405 'framingmediatypes': [FRAMINGTYPE],
405 }
406 }
406
407
407 for command, entry in wireproto.commandsv2.items():
408 for command, entry in COMMANDS.items():
408 caps['commands'][command] = {
409 caps['commands'][command] = {
409 'args': entry.args,
410 'args': entry.args,
410 'permissions': [entry.permission],
411 'permissions': [entry.permission],
@@ -445,11 +446,11 b' def wireprotocommand(name, args=None, pe'
445 'must be declared as dicts')
446 'must be declared as dicts')
446
447
447 def register(func):
448 def register(func):
448 if name in wireproto.commandsv2:
449 if name in COMMANDS:
449 raise error.ProgrammingError('%s command already registered '
450 raise error.ProgrammingError('%s command already registered '
450 'for version 2' % name)
451 'for version 2' % name)
451
452
452 wireproto.commandsv2[name] = wireprototypes.commandentry(
453 COMMANDS[name] = wireprototypes.commandentry(
453 func, args=args, transports=transports, permission=permission)
454 func, args=args, transports=transports, permission=permission)
454
455
455 return func
456 return func
General Comments 0
You need to be logged in to leave comments. Login now