##// END OF EJS Templates
wireprototypes: convert `baseprotocolhandler` to a Protocol class...
Matt Harbison -
r53017:47981c4b default
parent child Browse files
Show More
@@ -7,6 +7,10 from __future__ import annotations
7
7
8 import typing
8 import typing
9
9
10 from typing import (
11 Protocol,
12 )
13
10 from .node import (
14 from .node import (
11 bin,
15 bin,
12 hex,
16 hex,
@@ -23,7 +27,6 from . import (
23 error,
27 error,
24 util,
28 util,
25 )
29 )
26 from .interfaces import util as interfaceutil
27 from .utils import compression
30 from .utils import compression
28
31
29 # Names of the SSH protocol implementations.
32 # Names of the SSH protocol implementations.
@@ -181,7 +184,7 GETBUNDLE_ARGUMENTS = {
181 }
184 }
182
185
183
186
184 class baseprotocolhandler(interfaceutil.Interface):
187 class baseprotocolhandler(Protocol):
185 """Abstract base class for wire protocol handlers.
188 """Abstract base class for wire protocol handlers.
186
189
187 A wire protocol handler serves as an interface between protocol command
190 A wire protocol handler serves as an interface between protocol command
@@ -190,14 +193,13 class baseprotocolhandler(interfaceutil.
190 the request, handle response types, etc.
193 the request, handle response types, etc.
191 """
194 """
192
195
193 name = interfaceutil.Attribute(
196 name: bytes
194 """The name of the protocol implementation.
197 """The name of the protocol implementation.
195
198
196 Used for uniquely identifying the transport type.
199 Used for uniquely identifying the transport type.
197 """
200 """
198 )
199
201
200 def getargs(args):
202 def getargs(self, args):
201 """return the value for arguments in <args>
203 """return the value for arguments in <args>
202
204
203 For version 1 transports, returns a list of values in the same
205 For version 1 transports, returns a list of values in the same
@@ -205,20 +207,20 class baseprotocolhandler(interfaceutil.
205 a dict mapping argument name to value.
207 a dict mapping argument name to value.
206 """
208 """
207
209
208 def getprotocaps():
210 def getprotocaps(self):
209 """Returns the list of protocol-level capabilities of client
211 """Returns the list of protocol-level capabilities of client
210
212
211 Returns a list of capabilities as declared by the client for
213 Returns a list of capabilities as declared by the client for
212 the current request (or connection for stateful protocol handlers)."""
214 the current request (or connection for stateful protocol handlers)."""
213
215
214 def getpayload():
216 def getpayload(self):
215 """Provide a generator for the raw payload.
217 """Provide a generator for the raw payload.
216
218
217 The caller is responsible for ensuring that the full payload is
219 The caller is responsible for ensuring that the full payload is
218 processed.
220 processed.
219 """
221 """
220
222
221 def mayberedirectstdio():
223 def mayberedirectstdio(self):
222 """Context manager to possibly redirect stdio.
224 """Context manager to possibly redirect stdio.
223
225
224 The context manager yields a file-object like object that receives
226 The context manager yields a file-object like object that receives
@@ -231,10 +233,10 class baseprotocolhandler(interfaceutil.
231 won't be captured.
233 won't be captured.
232 """
234 """
233
235
234 def client():
236 def client(self):
235 """Returns a string representation of this client (as bytes)."""
237 """Returns a string representation of this client (as bytes)."""
236
238
237 def addcapabilities(repo, caps):
239 def addcapabilities(self, repo, caps):
238 """Adds advertised capabilities specific to this protocol.
240 """Adds advertised capabilities specific to this protocol.
239
241
240 Receives the list of capabilities collected so far.
242 Receives the list of capabilities collected so far.
@@ -242,7 +244,7 class baseprotocolhandler(interfaceutil.
242 Returns a list of capabilities. The passed in argument can be returned.
244 Returns a list of capabilities. The passed in argument can be returned.
243 """
245 """
244
246
245 def checkperm(perm):
247 def checkperm(self, perm):
246 """Validate that the client has permissions to perform a request.
248 """Validate that the client has permissions to perform a request.
247
249
248 The argument is the permission required to proceed. If the client
250 The argument is the permission required to proceed. If the client
General Comments 0
You need to be logged in to leave comments. Login now