Mercurial > public > mercurial-scm > hg
comparison mercurial/httppeer.py @ 37609:01bfe5ad0c53
httppeer: implement ipeerconnection
This is low hanging fruit. We might as well start somewhere.
Differential Revision: https://phab.mercurial-scm.org/D3254
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 11 Apr 2018 11:03:45 -0700 |
parents | 8a73132214a3 |
children | ae8730877371 |
comparison
equal
deleted
inserted
replaced
37608:fa4b39bb0a07 | 37609:01bfe5ad0c53 |
---|---|
17 | 17 |
18 from .i18n import _ | 18 from .i18n import _ |
19 from .thirdparty import ( | 19 from .thirdparty import ( |
20 cbor, | 20 cbor, |
21 ) | 21 ) |
22 from .thirdparty.zope import ( | |
23 interface as zi, | |
24 ) | |
22 from . import ( | 25 from . import ( |
23 bundle2, | 26 bundle2, |
24 error, | 27 error, |
25 httpconnection, | 28 httpconnection, |
26 pycompat, | 29 pycompat, |
30 repository, | |
27 statichttprepo, | 31 statichttprepo, |
28 url as urlmod, | 32 url as urlmod, |
29 util, | 33 util, |
30 wireproto, | 34 wireproto, |
31 wireprotoframing, | 35 wireprotoframing, |
511 | 515 |
512 def _abort(self, exception): | 516 def _abort(self, exception): |
513 raise exception | 517 raise exception |
514 | 518 |
515 # TODO implement interface for version 2 peers | 519 # TODO implement interface for version 2 peers |
520 @zi.implementer(repository.ipeerconnection) | |
516 class httpv2peer(object): | 521 class httpv2peer(object): |
517 def __init__(self, ui, repourl, apipath, opener, requestbuilder, | 522 def __init__(self, ui, repourl, apipath, opener, requestbuilder, |
518 apidescriptor): | 523 apidescriptor): |
519 self.ui = ui | 524 self.ui = ui |
520 | 525 |
521 if repourl.endswith('/'): | 526 if repourl.endswith('/'): |
522 repourl = repourl[:-1] | 527 repourl = repourl[:-1] |
523 | 528 |
524 self.url = repourl | 529 self._url = repourl |
525 self._apipath = apipath | 530 self._apipath = apipath |
526 self._opener = opener | 531 self._opener = opener |
527 self._requestbuilder = requestbuilder | 532 self._requestbuilder = requestbuilder |
528 self._descriptor = apidescriptor | 533 self._descriptor = apidescriptor |
529 | 534 |
535 # Start of ipeerconnection. | |
536 | |
537 def url(self): | |
538 return self._url | |
539 | |
540 def local(self): | |
541 return None | |
542 | |
543 def peer(self): | |
544 return self | |
545 | |
546 def canpush(self): | |
547 # TODO change once implemented. | |
548 return False | |
549 | |
530 def close(self): | 550 def close(self): |
531 pass | 551 pass |
552 | |
553 # End of ipeerconnection. | |
532 | 554 |
533 # TODO require to be part of a batched primitive, use futures. | 555 # TODO require to be part of a batched primitive, use futures. |
534 def _call(self, name, **args): | 556 def _call(self, name, **args): |
535 """Call a wire protocol command with arguments.""" | 557 """Call a wire protocol command with arguments.""" |
536 | 558 |
552 permission = { | 574 permission = { |
553 'push': 'rw', | 575 'push': 'rw', |
554 'pull': 'ro', | 576 'pull': 'ro', |
555 }[permission] | 577 }[permission] |
556 | 578 |
557 url = '%s/%s/%s/%s' % (self.url, self._apipath, permission, name) | 579 url = '%s/%s/%s/%s' % (self._url, self._apipath, permission, name) |
558 | 580 |
559 # TODO this should be part of a generic peer for the frame-based | 581 # TODO this should be part of a generic peer for the frame-based |
560 # protocol. | 582 # protocol. |
561 reactor = wireprotoframing.clientreactor(hasmultiplesend=False, | 583 reactor = wireprotoframing.clientreactor(hasmultiplesend=False, |
562 buffersends=True) | 584 buffersends=True) |