mercurial/repository.py
changeset 33802 a0aad86b3b6a
parent 33801 558f5b2ee10e
child 37181 0dfb5672f015
equal deleted inserted replaced
33801:558f5b2ee10e 33802:a0aad86b3b6a
     7 
     7 
     8 from __future__ import absolute_import
     8 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 
    15     This is the base interface for representing a connection to a repository.
    20     This is the base interface for representing a connection to a repository.
    16     It holds basic properties and methods applicable to all peer types.
    21     It holds basic properties and methods applicable to all peer types.
   226 
   231 
   227         Not all peers or wire protocol implementations may actually batch method
   232         Not all peers or wire protocol implementations may actually batch method
   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."""