comparison mercurial/httppeer.py @ 40171:dac438b7346e

httppeer: expose API descriptor on httpv2peer The API descriptor in wireprotov2 is much more expressive than space-delimited tokens and it will be difficult to define methods to query it in all of the ways we'll want to query it. So let's just declare defeat and expose the API descriptor on the peer instance. As part of this, we define a new interface for version 2 peers, fulfilling a TODO in the process. Differential Revision: https://phab.mercurial-scm.org/D4974
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 03 Oct 2018 13:07:28 -0700
parents 762ef19a07e3
children 588f1e9a4d16
comparison
equal deleted inserted replaced
40170:f7ff5b4fe745 40171:dac438b7346e
742 # Called in a thread to read the response. 742 # Called in a thread to read the response.
743 743
744 while handler.readdata(resp): 744 while handler.readdata(resp):
745 pass 745 pass
746 746
747 # TODO implement interface for version 2 peers 747 @interfaceutil.implementer(repository.ipeerv2)
748 @interfaceutil.implementer(repository.ipeerconnection,
749 repository.ipeercapabilities,
750 repository.ipeerrequests)
751 class httpv2peer(object): 748 class httpv2peer(object):
752 def __init__(self, ui, repourl, apipath, opener, requestbuilder, 749 def __init__(self, ui, repourl, apipath, opener, requestbuilder,
753 apidescriptor): 750 apidescriptor):
754 self.ui = ui 751 self.ui = ui
752 self.apidescriptor = apidescriptor
755 753
756 if repourl.endswith('/'): 754 if repourl.endswith('/'):
757 repourl = repourl[:-1] 755 repourl = repourl[:-1]
758 756
759 self._url = repourl 757 self._url = repourl
760 self._apipath = apipath 758 self._apipath = apipath
761 self._apiurl = '%s/%s' % (repourl, apipath) 759 self._apiurl = '%s/%s' % (repourl, apipath)
762 self._opener = opener 760 self._opener = opener
763 self._requestbuilder = requestbuilder 761 self._requestbuilder = requestbuilder
764 self._descriptor = apidescriptor
765 762
766 self._redirect = wireprotov2peer.supportedredirects(ui, apidescriptor) 763 self._redirect = wireprotov2peer.supportedredirects(ui, apidescriptor)
767 764
768 # Start of ipeerconnection. 765 # Start of ipeerconnection.
769 766
804 if name in ('bundle2'): 801 if name in ('bundle2'):
805 return True 802 return True
806 803
807 # Alias command-* to presence of command of that name. 804 # Alias command-* to presence of command of that name.
808 if name.startswith('command-'): 805 if name.startswith('command-'):
809 return name[len('command-'):] in self._descriptor['commands'] 806 return name[len('command-'):] in self.apidescriptor['commands']
810 807
811 return False 808 return False
812 809
813 def requirecap(self, name, purpose): 810 def requirecap(self, name, purpose):
814 if self.capable(name): 811 if self.capable(name):
824 with self.commandexecutor() as e: 821 with self.commandexecutor() as e:
825 return e.callcommand(name, args).result() 822 return e.callcommand(name, args).result()
826 823
827 def commandexecutor(self): 824 def commandexecutor(self):
828 return httpv2executor(self.ui, self._opener, self._requestbuilder, 825 return httpv2executor(self.ui, self._opener, self._requestbuilder,
829 self._apiurl, self._descriptor, self._redirect) 826 self._apiurl, self.apidescriptor, self._redirect)
830 827
831 # Registry of API service names to metadata about peers that handle it. 828 # Registry of API service names to metadata about peers that handle it.
832 # 829 #
833 # The following keys are meaningful: 830 # The following keys are meaningful:
834 # 831 #