Show More
@@ -9,6 +9,11 b' from __future__ import absolute_import' | |||||
9 |
|
9 | |||
10 | import abc |
|
10 | import abc | |
11 |
|
11 | |||
|
12 | from .i18n import _ | |||
|
13 | from . import ( | |||
|
14 | error, | |||
|
15 | ) | |||
|
16 | ||||
12 | class _basepeer(object): |
|
17 | class _basepeer(object): | |
13 | """Represents a "connection" to a repository. |
|
18 | """Represents a "connection" to a repository. | |
14 |
|
19 | |||
@@ -228,5 +233,36 b' class peer(_basepeer, _basewirecommands)' | |||||
228 | calls. However, they must all support this API. |
|
233 | calls. However, they must all support this API. | |
229 | """ |
|
234 | """ | |
230 |
|
235 | |||
|
236 | def capable(self, name): | |||
|
237 | """Determine support for a named capability. | |||
|
238 | ||||
|
239 | Returns ``False`` if capability not supported. | |||
|
240 | ||||
|
241 | Returns ``True`` if boolean capability is supported. Returns a string | |||
|
242 | if capability support is non-boolean. | |||
|
243 | """ | |||
|
244 | caps = self.capabilities() | |||
|
245 | if name in caps: | |||
|
246 | return True | |||
|
247 | ||||
|
248 | name = '%s=' % name | |||
|
249 | for cap in caps: | |||
|
250 | if cap.startswith(name): | |||
|
251 | return cap[len(name):] | |||
|
252 | ||||
|
253 | return False | |||
|
254 | ||||
|
255 | def requirecap(self, name, purpose): | |||
|
256 | """Require a capability to be present. | |||
|
257 | ||||
|
258 | Raises a ``CapabilityError`` if the capability isn't present. | |||
|
259 | """ | |||
|
260 | if self.capable(name): | |||
|
261 | return | |||
|
262 | ||||
|
263 | raise error.CapabilityError( | |||
|
264 | _('cannot %s; remote repository does not support the %r ' | |||
|
265 | 'capability') % (purpose, name)) | |||
|
266 | ||||
231 | class legacypeer(peer, _baselegacywirecommands): |
|
267 | class legacypeer(peer, _baselegacywirecommands): | |
232 | """peer but with support for legacy wire protocol commands.""" |
|
268 | """peer but with support for legacy wire protocol commands.""" |
General Comments 0
You need to be logged in to leave comments.
Login now