##// END OF EJS Templates
wireproto: reimplement dispatch() for version 2 server...
Gregory Szorc -
r37800:99accae4 default
parent child Browse files
Show More
@@ -69,20 +69,10 b' def getdispatchrepo(repo, proto, command'
69 def dispatch(repo, proto, command):
69 def dispatch(repo, proto, command):
70 repo = getdispatchrepo(repo, proto, command)
70 repo = getdispatchrepo(repo, proto, command)
71
71
72 transportversion = wireprototypes.TRANSPORTS[proto.name]['version']
72 func, spec = commands[command]
73 commandtable = commandsv2 if transportversion == 2 else commands
74 func, spec = commandtable[command]
75
76 args = proto.getargs(spec)
73 args = proto.getargs(spec)
77
74
78 # Version 1 protocols define arguments as a list. Version 2 uses a dict.
75 return func(repo, proto, *args)
79 if isinstance(args, list):
80 return func(repo, proto, *args)
81 elif isinstance(args, dict):
82 return func(repo, proto, **args)
83 else:
84 raise error.ProgrammingError('unexpected type returned from '
85 'proto.getargs(): %s' % type(args))
86
76
87 def options(cmd, keys, others):
77 def options(cmd, keys, others):
88 opts = {}
78 opts = {}
@@ -296,7 +296,7 b' def _httpv2runcommand(ui, repo, req, res'
296 res.setbodybytes(_('command in frame must match command in URL'))
296 res.setbodybytes(_('command in frame must match command in URL'))
297 return True
297 return True
298
298
299 rsp = wireproto.dispatch(repo, proto, command['command'])
299 rsp = dispatch(repo, proto, command['command'])
300
300
301 res.status = b'200 OK'
301 res.status = b'200 OK'
302 res.headers[b'Content-Type'] = FRAMINGTYPE
302 res.headers[b'Content-Type'] = FRAMINGTYPE
@@ -328,6 +328,17 b' def _httpv2runcommand(ui, repo, req, res'
328 raise error.ProgrammingError('unhandled event from reactor: %s' %
328 raise error.ProgrammingError('unhandled event from reactor: %s' %
329 action)
329 action)
330
330
331 def getdispatchrepo(repo, proto, command):
332 return repo.filtered('served')
333
334 def dispatch(repo, proto, command):
335 repo = getdispatchrepo(repo, proto, command)
336
337 func, spec = wireproto.commandsv2[command]
338 args = proto.getargs(spec)
339
340 return func(repo, proto, **args)
341
331 @zi.implementer(wireprototypes.baseprotocolhandler)
342 @zi.implementer(wireprototypes.baseprotocolhandler)
332 class httpv2protocolhandler(object):
343 class httpv2protocolhandler(object):
333 def __init__(self, req, ui, args=None):
344 def __init__(self, req, ui, args=None):
General Comments 0
You need to be logged in to leave comments. Login now