diff mercurial/wireprototypes.py @ 37296:78103e4138b1

wireproto: port protocol handler to zope.interface zope.interface is superior to the abc module. Let's port to it. As part of this, we add tests for interface conformance for classes implementing the interface. Differential Revision: https://phab.mercurial-scm.org/D2983
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 23 Mar 2018 16:24:53 -0700
parents 27527d8cff5c
children afcfdf53e4b5
line wrap: on
line diff
--- a/mercurial/wireprototypes.py	Wed Mar 28 10:40:41 2018 -0700
+++ b/mercurial/wireprototypes.py	Fri Mar 23 16:24:53 2018 -0700
@@ -5,7 +5,9 @@
 
 from __future__ import absolute_import
 
-import abc
+from .thirdparty.zope import (
+    interface as zi,
+)
 
 # Names of the SSH protocol implementations.
 SSHV1 = 'ssh-v1'
@@ -95,7 +97,7 @@
     def __init__(self, gen=None):
         self.gen = gen
 
-class baseprotocolhandler(object):
+class baseprotocolhandler(zi.Interface):
     """Abstract base class for wire protocol handlers.
 
     A wire protocol handler serves as an interface between protocol command
@@ -104,30 +106,24 @@
     the request, handle response types, etc.
     """
 
-    __metaclass__ = abc.ABCMeta
-
-    @abc.abstractproperty
-    def name(self):
+    name = zi.Attribute(
         """The name of the protocol implementation.
 
         Used for uniquely identifying the transport type.
-        """
+        """)
 
-    @abc.abstractmethod
-    def getargs(self, args):
+    def getargs(args):
         """return the value for arguments in <args>
 
         returns a list of values (same order as <args>)"""
 
-    @abc.abstractmethod
-    def forwardpayload(self, fp):
+    def forwardpayload(fp):
         """Read the raw payload and forward to a file.
 
         The payload is read in full before the function returns.
         """
 
-    @abc.abstractmethod
-    def mayberedirectstdio(self):
+    def mayberedirectstdio():
         """Context manager to possibly redirect stdio.
 
         The context manager yields a file-object like object that receives
@@ -140,12 +136,10 @@
         won't be captured.
         """
 
-    @abc.abstractmethod
-    def client(self):
+    def client():
         """Returns a string representation of this client (as bytes)."""
 
-    @abc.abstractmethod
-    def addcapabilities(self, repo, caps):
+    def addcapabilities(repo, caps):
         """Adds advertised capabilities specific to this protocol.
 
         Receives the list of capabilities collected so far.
@@ -153,8 +147,7 @@
         Returns a list of capabilities. The passed in argument can be returned.
         """
 
-    @abc.abstractmethod
-    def checkperm(self, perm):
+    def checkperm(perm):
         """Validate that the client has permissions to perform a request.
 
         The argument is the permission required to proceed. If the client