3 # This software may be used and distributed according to the terms of the |
3 # This software may be used and distributed according to the terms of the |
4 # GNU General Public License version 2 or any later version. |
4 # GNU General Public License version 2 or any later version. |
5 |
5 |
6 from __future__ import absolute_import |
6 from __future__ import absolute_import |
7 |
7 |
8 import abc |
8 from .thirdparty.zope import ( |
|
9 interface as zi, |
|
10 ) |
9 |
11 |
10 # Names of the SSH protocol implementations. |
12 # Names of the SSH protocol implementations. |
11 SSHV1 = 'ssh-v1' |
13 SSHV1 = 'ssh-v1' |
12 # These are advertised over the wire. Increment the counters at the end |
14 # These are advertised over the wire. Increment the counters at the end |
13 # to reflect BC breakages. |
15 # to reflect BC breakages. |
93 using the application/mercurial-0.1 media type. |
95 using the application/mercurial-0.1 media type. |
94 """ |
96 """ |
95 def __init__(self, gen=None): |
97 def __init__(self, gen=None): |
96 self.gen = gen |
98 self.gen = gen |
97 |
99 |
98 class baseprotocolhandler(object): |
100 class baseprotocolhandler(zi.Interface): |
99 """Abstract base class for wire protocol handlers. |
101 """Abstract base class for wire protocol handlers. |
100 |
102 |
101 A wire protocol handler serves as an interface between protocol command |
103 A wire protocol handler serves as an interface between protocol command |
102 handlers and the wire protocol transport layer. Protocol handlers provide |
104 handlers and the wire protocol transport layer. Protocol handlers provide |
103 methods to read command arguments, redirect stdio for the duration of |
105 methods to read command arguments, redirect stdio for the duration of |
104 the request, handle response types, etc. |
106 the request, handle response types, etc. |
105 """ |
107 """ |
106 |
108 |
107 __metaclass__ = abc.ABCMeta |
109 name = zi.Attribute( |
108 |
|
109 @abc.abstractproperty |
|
110 def name(self): |
|
111 """The name of the protocol implementation. |
110 """The name of the protocol implementation. |
112 |
111 |
113 Used for uniquely identifying the transport type. |
112 Used for uniquely identifying the transport type. |
114 """ |
113 """) |
115 |
114 |
116 @abc.abstractmethod |
115 def getargs(args): |
117 def getargs(self, args): |
|
118 """return the value for arguments in <args> |
116 """return the value for arguments in <args> |
119 |
117 |
120 returns a list of values (same order as <args>)""" |
118 returns a list of values (same order as <args>)""" |
121 |
119 |
122 @abc.abstractmethod |
120 def forwardpayload(fp): |
123 def forwardpayload(self, fp): |
|
124 """Read the raw payload and forward to a file. |
121 """Read the raw payload and forward to a file. |
125 |
122 |
126 The payload is read in full before the function returns. |
123 The payload is read in full before the function returns. |
127 """ |
124 """ |
128 |
125 |
129 @abc.abstractmethod |
126 def mayberedirectstdio(): |
130 def mayberedirectstdio(self): |
|
131 """Context manager to possibly redirect stdio. |
127 """Context manager to possibly redirect stdio. |
132 |
128 |
133 The context manager yields a file-object like object that receives |
129 The context manager yields a file-object like object that receives |
134 stdout and stderr output when the context manager is active. Or it |
130 stdout and stderr output when the context manager is active. Or it |
135 yields ``None`` if no I/O redirection occurs. |
131 yields ``None`` if no I/O redirection occurs. |
138 so it may be sent in the response. Some transports support streaming |
134 so it may be sent in the response. Some transports support streaming |
139 stdio to the client in real time. For these transports, stdio output |
135 stdio to the client in real time. For these transports, stdio output |
140 won't be captured. |
136 won't be captured. |
141 """ |
137 """ |
142 |
138 |
143 @abc.abstractmethod |
139 def client(): |
144 def client(self): |
|
145 """Returns a string representation of this client (as bytes).""" |
140 """Returns a string representation of this client (as bytes).""" |
146 |
141 |
147 @abc.abstractmethod |
142 def addcapabilities(repo, caps): |
148 def addcapabilities(self, repo, caps): |
|
149 """Adds advertised capabilities specific to this protocol. |
143 """Adds advertised capabilities specific to this protocol. |
150 |
144 |
151 Receives the list of capabilities collected so far. |
145 Receives the list of capabilities collected so far. |
152 |
146 |
153 Returns a list of capabilities. The passed in argument can be returned. |
147 Returns a list of capabilities. The passed in argument can be returned. |
154 """ |
148 """ |
155 |
149 |
156 @abc.abstractmethod |
150 def checkperm(perm): |
157 def checkperm(self, perm): |
|
158 """Validate that the client has permissions to perform a request. |
151 """Validate that the client has permissions to perform a request. |
159 |
152 |
160 The argument is the permission required to proceed. If the client |
153 The argument is the permission required to proceed. If the client |
161 doesn't have that permission, the exception should raise or abort |
154 doesn't have that permission, the exception should raise or abort |
162 in a protocol specific manner. |
155 in a protocol specific manner. |