Mercurial > hg
comparison mercurial/wireproto.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 | 038bcb759b75 |
children | 2f7290555c96 |
comparison
equal
deleted
inserted
replaced
36072:341c886e411e | 36073:cd6ab329c5c7 |
---|---|
29 pushkey as pushkeymod, | 29 pushkey as pushkeymod, |
30 pycompat, | 30 pycompat, |
31 repository, | 31 repository, |
32 streamclone, | 32 streamclone, |
33 util, | 33 util, |
34 wireprototypes, | |
34 ) | 35 ) |
35 | 36 |
36 urlerr = util.urlerr | 37 urlerr = util.urlerr |
37 urlreq = util.urlreq | 38 urlreq = util.urlreq |
39 | |
40 ooberror = wireprototypes.ooberror | |
41 pushres = wireprototypes.pushres | |
42 pusherr = wireprototypes.pusherr | |
43 streamres = wireprototypes.streamres | |
44 streamres_legacy = wireprototypes.streamreslegacy | |
38 | 45 |
39 bundle2requiredmain = _('incompatible Mercurial client; bundle2 required') | 46 bundle2requiredmain = _('incompatible Mercurial client; bundle2 required') |
40 bundle2requiredhint = _('see https://www.mercurial-scm.org/wiki/' | 47 bundle2requiredhint = _('see https://www.mercurial-scm.org/wiki/' |
41 'IncompatibleClient') | 48 'IncompatibleClient') |
42 bundle2required = '%s\n(%s)\n' % (bundle2requiredmain, bundle2requiredhint) | 49 bundle2required = '%s\n(%s)\n' % (bundle2requiredmain, bundle2requiredhint) |
475 raise NotImplementedError() | 482 raise NotImplementedError() |
476 | 483 |
477 # server side | 484 # server side |
478 | 485 |
479 # wire protocol command can either return a string or one of these classes. | 486 # wire protocol command can either return a string or one of these classes. |
480 class streamres(object): | |
481 """wireproto reply: binary stream | |
482 | |
483 The call was successful and the result is a stream. | |
484 | |
485 Accepts a generator containing chunks of data to be sent to the client. | |
486 | |
487 ``prefer_uncompressed`` indicates that the data is expected to be | |
488 uncompressable and that the stream should therefore use the ``none`` | |
489 engine. | |
490 """ | |
491 def __init__(self, gen=None, prefer_uncompressed=False): | |
492 self.gen = gen | |
493 self.prefer_uncompressed = prefer_uncompressed | |
494 | |
495 class streamres_legacy(object): | |
496 """wireproto reply: uncompressed binary stream | |
497 | |
498 The call was successful and the result is a stream. | |
499 | |
500 Accepts a generator containing chunks of data to be sent to the client. | |
501 | |
502 Like ``streamres``, but sends an uncompressed data for "version 1" clients | |
503 using the application/mercurial-0.1 media type. | |
504 """ | |
505 def __init__(self, gen=None): | |
506 self.gen = gen | |
507 | |
508 class pushres(object): | |
509 """wireproto reply: success with simple integer return | |
510 | |
511 The call was successful and returned an integer contained in `self.res`. | |
512 """ | |
513 def __init__(self, res, output): | |
514 self.res = res | |
515 self.output = output | |
516 | |
517 class pusherr(object): | |
518 """wireproto reply: failure | |
519 | |
520 The call failed. The `self.res` attribute contains the error message. | |
521 """ | |
522 def __init__(self, res, output): | |
523 self.res = res | |
524 self.output = output | |
525 | |
526 class ooberror(object): | |
527 """wireproto reply: failure of a batch of operation | |
528 | |
529 Something failed during a batch call. The error message is stored in | |
530 `self.message`. | |
531 """ | |
532 def __init__(self, message): | |
533 self.message = message | |
534 | 487 |
535 def getdispatchrepo(repo, proto, command): | 488 def getdispatchrepo(repo, proto, command): |
536 """Obtain the repo used for processing wire protocol commands. | 489 """Obtain the repo used for processing wire protocol commands. |
537 | 490 |
538 The intent of this function is to serve as a monkeypatch point for | 491 The intent of this function is to serve as a monkeypatch point for |