Mercurial > public > mercurial-scm > hg
comparison mercurial/wireprotoserver.py @ 36073:cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
We'll be introducing more types as part of wire protocol version 2.
These types are shared between the command handling code (in
wireproto.py) and the protocol/transport code in wireprotoserver.py.
So they need to go in a new module to prevent a cycle.
The types are aliased into the wireproto module, so API compatibility
is preserved.
Differential Revision: https://phab.mercurial-scm.org/D2088
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 07 Feb 2018 16:29:05 -0800 |
parents | 341c886e411e |
children | 2f7290555c96 |
comparison
equal
deleted
inserted
replaced
36072:341c886e411e | 36073:cd6ab329c5c7 |
---|---|
18 error, | 18 error, |
19 hook, | 19 hook, |
20 pycompat, | 20 pycompat, |
21 util, | 21 util, |
22 wireproto, | 22 wireproto, |
23 wireprototypes, | |
23 ) | 24 ) |
24 | 25 |
25 stringio = util.stringio | 26 stringio = util.stringio |
26 | 27 |
27 urlerr = util.urlerr | 28 urlerr = util.urlerr |
271 return [] | 272 return [] |
272 | 273 |
273 if isinstance(rsp, bytes): | 274 if isinstance(rsp, bytes): |
274 req.respond(HTTP_OK, HGTYPE, body=rsp) | 275 req.respond(HTTP_OK, HGTYPE, body=rsp) |
275 return [] | 276 return [] |
276 elif isinstance(rsp, wireproto.streamres_legacy): | 277 elif isinstance(rsp, wireprototypes.streamreslegacy): |
277 gen = rsp.gen | 278 gen = rsp.gen |
278 req.respond(HTTP_OK, HGTYPE) | 279 req.respond(HTTP_OK, HGTYPE) |
279 return gen | 280 return gen |
280 elif isinstance(rsp, wireproto.streamres): | 281 elif isinstance(rsp, wireprototypes.streamres): |
281 gen = rsp.gen | 282 gen = rsp.gen |
282 | 283 |
283 # This code for compression should not be streamres specific. It | 284 # This code for compression should not be streamres specific. It |
284 # is here because we only compress streamres at the moment. | 285 # is here because we only compress streamres at the moment. |
285 mediatype, engine, engineopts = _httpresponsetype( | 286 mediatype, engine, engineopts = _httpresponsetype( |
289 if mediatype == HGTYPE2: | 290 if mediatype == HGTYPE2: |
290 gen = genversion2(gen, engine, engineopts) | 291 gen = genversion2(gen, engine, engineopts) |
291 | 292 |
292 req.respond(HTTP_OK, mediatype) | 293 req.respond(HTTP_OK, mediatype) |
293 return gen | 294 return gen |
294 elif isinstance(rsp, wireproto.pushres): | 295 elif isinstance(rsp, wireprototypes.pushres): |
295 rsp = '%d\n%s' % (rsp.res, rsp.output) | 296 rsp = '%d\n%s' % (rsp.res, rsp.output) |
296 req.respond(HTTP_OK, HGTYPE, body=rsp) | 297 req.respond(HTTP_OK, HGTYPE, body=rsp) |
297 return [] | 298 return [] |
298 elif isinstance(rsp, wireproto.pusherr): | 299 elif isinstance(rsp, wireprototypes.pusherr): |
299 # This is the httplib workaround documented in _handlehttperror(). | 300 # This is the httplib workaround documented in _handlehttperror(). |
300 req.drain() | 301 req.drain() |
301 | 302 |
302 rsp = '0\n%s\n' % rsp.res | 303 rsp = '0\n%s\n' % rsp.res |
303 req.respond(HTTP_OK, HGTYPE, body=rsp) | 304 req.respond(HTTP_OK, HGTYPE, body=rsp) |
304 return [] | 305 return [] |
305 elif isinstance(rsp, wireproto.ooberror): | 306 elif isinstance(rsp, wireprototypes.ooberror): |
306 rsp = rsp.message | 307 rsp = rsp.message |
307 req.respond(HTTP_OK, HGERRTYPE, body=rsp) | 308 req.respond(HTTP_OK, HGERRTYPE, body=rsp) |
308 return [] | 309 return [] |
309 raise error.ProgrammingError('hgweb.protocol internal failure', rsp) | 310 raise error.ProgrammingError('hgweb.protocol internal failure', rsp) |
310 | 311 |
432 if cmd and wireproto.commands.commandavailable(cmd, self._proto): | 433 if cmd and wireproto.commands.commandavailable(cmd, self._proto): |
433 rsp = wireproto.dispatch(self._repo, self._proto, cmd) | 434 rsp = wireproto.dispatch(self._repo, self._proto, cmd) |
434 | 435 |
435 if isinstance(rsp, bytes): | 436 if isinstance(rsp, bytes): |
436 _sshv1respondbytes(self._fout, rsp) | 437 _sshv1respondbytes(self._fout, rsp) |
437 elif isinstance(rsp, wireproto.streamres): | 438 elif isinstance(rsp, wireprototypes.streamres): |
438 _sshv1respondstream(self._fout, rsp) | 439 _sshv1respondstream(self._fout, rsp) |
439 elif isinstance(rsp, wireproto.streamres_legacy): | 440 elif isinstance(rsp, wireprototypes.streamreslegacy): |
440 _sshv1respondstream(self._fout, rsp) | 441 _sshv1respondstream(self._fout, rsp) |
441 elif isinstance(rsp, wireproto.pushres): | 442 elif isinstance(rsp, wireprototypes.pushres): |
442 _sshv1respondbytes(self._fout, b'') | 443 _sshv1respondbytes(self._fout, b'') |
443 _sshv1respondbytes(self._fout, bytes(rsp.res)) | 444 _sshv1respondbytes(self._fout, bytes(rsp.res)) |
444 elif isinstance(rsp, wireproto.pusherr): | 445 elif isinstance(rsp, wireprototypes.pusherr): |
445 _sshv1respondbytes(self._fout, rsp.res) | 446 _sshv1respondbytes(self._fout, rsp.res) |
446 elif isinstance(rsp, wireproto.ooberror): | 447 elif isinstance(rsp, wireprototypes.ooberror): |
447 _sshv1respondooberror(self._fout, self._ui.ferr, rsp.message) | 448 _sshv1respondooberror(self._fout, self._ui.ferr, rsp.message) |
448 else: | 449 else: |
449 raise error.ProgrammingError('unhandled response type from ' | 450 raise error.ProgrammingError('unhandled response type from ' |
450 'wire protocol command: %s' % rsp) | 451 'wire protocol command: %s' % rsp) |
451 elif cmd: | 452 elif cmd: |