##// END OF EJS Templates
wireprototypes: move baseprotocolhandler from wireprotoserver...
Gregory Szorc -
r36389:0c231df1 default
parent child Browse files
Show More
@@ -6,7 +6,6 b''
6
6
7 from __future__ import absolute_import
7 from __future__ import absolute_import
8
8
9 import abc
10 import contextlib
9 import contextlib
11 import struct
10 import struct
12 import sys
11 import sys
@@ -39,55 +38,6 b" SSHV1 = 'ssh-v1'"
39 # to reflect BC breakages.
38 # to reflect BC breakages.
40 SSHV2 = 'exp-ssh-v2-0001'
39 SSHV2 = 'exp-ssh-v2-0001'
41
40
42 class baseprotocolhandler(object):
43 """Abstract base class for wire protocol handlers.
44
45 A wire protocol handler serves as an interface between protocol command
46 handlers and the wire protocol transport layer. Protocol handlers provide
47 methods to read command arguments, redirect stdio for the duration of
48 the request, handle response types, etc.
49 """
50
51 __metaclass__ = abc.ABCMeta
52
53 @abc.abstractproperty
54 def name(self):
55 """The name of the protocol implementation.
56
57 Used for uniquely identifying the transport type.
58 """
59
60 @abc.abstractmethod
61 def getargs(self, args):
62 """return the value for arguments in <args>
63
64 returns a list of values (same order as <args>)"""
65
66 @abc.abstractmethod
67 def forwardpayload(self, fp):
68 """Read the raw payload and forward to a file.
69
70 The payload is read in full before the function returns.
71 """
72
73 @abc.abstractmethod
74 def mayberedirectstdio(self):
75 """Context manager to possibly redirect stdio.
76
77 The context manager yields a file-object like object that receives
78 stdout and stderr output when the context manager is active. Or it
79 yields ``None`` if no I/O redirection occurs.
80
81 The intent of this context manager is to capture stdio output
82 so it may be sent in the response. Some transports support streaming
83 stdio to the client in real time. For these transports, stdio output
84 won't be captured.
85 """
86
87 @abc.abstractmethod
88 def client(self):
89 """Returns a string representation of this client (as bytes)."""
90
91 def decodevaluefromheaders(req, headerprefix):
41 def decodevaluefromheaders(req, headerprefix):
92 """Decode a long value from multiple HTTP request headers.
42 """Decode a long value from multiple HTTP request headers.
93
43
@@ -105,7 +55,7 b' def decodevaluefromheaders(req, headerpr'
105
55
106 return ''.join(chunks)
56 return ''.join(chunks)
107
57
108 class httpv1protocolhandler(baseprotocolhandler):
58 class httpv1protocolhandler(wireprototypes.baseprotocolhandler):
109 def __init__(self, req, ui):
59 def __init__(self, req, ui):
110 self._req = req
60 self._req = req
111 self._ui = ui
61 self._ui = ui
@@ -364,7 +314,7 b' def _sshv1respondooberror(fout, ferr, rs'
364 fout.write(b'\n')
314 fout.write(b'\n')
365 fout.flush()
315 fout.flush()
366
316
367 class sshv1protocolhandler(baseprotocolhandler):
317 class sshv1protocolhandler(wireprototypes.baseprotocolhandler):
368 """Handler for requests services via version 1 of SSH protocol."""
318 """Handler for requests services via version 1 of SSH protocol."""
369 def __init__(self, ui, fin, fout):
319 def __init__(self, ui, fin, fout):
370 self._ui = ui
320 self._ui = ui
@@ -5,6 +5,8 b''
5
5
6 from __future__ import absolute_import
6 from __future__ import absolute_import
7
7
8 import abc
9
8 class bytesresponse(object):
10 class bytesresponse(object):
9 """A wire protocol response consisting of raw bytes."""
11 """A wire protocol response consisting of raw bytes."""
10 def __init__(self, data):
12 def __init__(self, data):
@@ -64,3 +66,52 b' class streamreslegacy(object):'
64 """
66 """
65 def __init__(self, gen=None):
67 def __init__(self, gen=None):
66 self.gen = gen
68 self.gen = gen
69
70 class baseprotocolhandler(object):
71 """Abstract base class for wire protocol handlers.
72
73 A wire protocol handler serves as an interface between protocol command
74 handlers and the wire protocol transport layer. Protocol handlers provide
75 methods to read command arguments, redirect stdio for the duration of
76 the request, handle response types, etc.
77 """
78
79 __metaclass__ = abc.ABCMeta
80
81 @abc.abstractproperty
82 def name(self):
83 """The name of the protocol implementation.
84
85 Used for uniquely identifying the transport type.
86 """
87
88 @abc.abstractmethod
89 def getargs(self, args):
90 """return the value for arguments in <args>
91
92 returns a list of values (same order as <args>)"""
93
94 @abc.abstractmethod
95 def forwardpayload(self, fp):
96 """Read the raw payload and forward to a file.
97
98 The payload is read in full before the function returns.
99 """
100
101 @abc.abstractmethod
102 def mayberedirectstdio(self):
103 """Context manager to possibly redirect stdio.
104
105 The context manager yields a file-object like object that receives
106 stdout and stderr output when the context manager is active. Or it
107 yields ``None`` if no I/O redirection occurs.
108
109 The intent of this context manager is to capture stdio output
110 so it may be sent in the response. Some transports support streaming
111 stdio to the client in real time. For these transports, stdio output
112 won't be captured.
113 """
114
115 @abc.abstractmethod
116 def client(self):
117 """Returns a string representation of this client (as bytes)."""
General Comments 0
You need to be logged in to leave comments. Login now