Mercurial > hg
diff mercurial/wireprototypes.py @ 52124:47981c4bfeee
wireprototypes: convert `baseprotocolhandler` to a Protocol class
The methodology for doing this is now known, and this is limited to two
implementing classes, so just make the changes.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 24 Oct 2024 20:47:12 -0400 |
parents | f4733654f144 |
children | e7812caacc3c |
line wrap: on
line diff
--- a/mercurial/wireprototypes.py Sat Oct 26 12:56:02 2024 +0200 +++ b/mercurial/wireprototypes.py Thu Oct 24 20:47:12 2024 -0400 @@ -7,6 +7,10 @@ import typing +from typing import ( + Protocol, +) + from .node import ( bin, hex, @@ -23,7 +27,6 @@ error, util, ) -from .interfaces import util as interfaceutil from .utils import compression # Names of the SSH protocol implementations. @@ -181,7 +184,7 @@ } -class baseprotocolhandler(interfaceutil.Interface): +class baseprotocolhandler(Protocol): """Abstract base class for wire protocol handlers. A wire protocol handler serves as an interface between protocol command @@ -190,14 +193,13 @@ the request, handle response types, etc. """ - name = interfaceutil.Attribute( - """The name of the protocol implementation. + name: bytes + """The name of the protocol implementation. - Used for uniquely identifying the transport type. - """ - ) + Used for uniquely identifying the transport type. + """ - def getargs(args): + def getargs(self, args): """return the value for arguments in <args> For version 1 transports, returns a list of values in the same @@ -205,20 +207,20 @@ a dict mapping argument name to value. """ - def getprotocaps(): + def getprotocaps(self): """Returns the list of protocol-level capabilities of client Returns a list of capabilities as declared by the client for the current request (or connection for stateful protocol handlers).""" - def getpayload(): + def getpayload(self): """Provide a generator for the raw payload. The caller is responsible for ensuring that the full payload is processed. """ - def mayberedirectstdio(): + def mayberedirectstdio(self): """Context manager to possibly redirect stdio. The context manager yields a file-object like object that receives @@ -231,10 +233,10 @@ won't be captured. """ - def client(): + def client(self): """Returns a string representation of this client (as bytes).""" - def addcapabilities(repo, caps): + def addcapabilities(self, repo, caps): """Adds advertised capabilities specific to this protocol. Receives the list of capabilities collected so far. @@ -242,7 +244,7 @@ Returns a list of capabilities. The passed in argument can be returned. """ - def checkperm(perm): + def checkperm(self, perm): """Validate that the client has permissions to perform a request. The argument is the permission required to proceed. If the client