_exceptions.py
changeset 0 b97547f5f1fa
child 1155 61149b53d441
equal deleted inserted replaced
-1:000000000000 0:b97547f5f1fa
       
     1 """Exceptions shared by different cubicweb packages.
       
     2 
       
     3 
       
     4 :organization: Logilab
       
     5 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     7 """
       
     8 __docformat__ = "restructuredtext en"
       
     9 
       
    10 from yams import ValidationError
       
    11 
       
    12 # abstract exceptions #########################################################
       
    13 
       
    14 class CubicWebException(Exception):
       
    15     """base class for cubicweb server exception"""
       
    16     msg = ""
       
    17     def __str__(self):
       
    18         if self.msg:
       
    19             if self.args:
       
    20                 return self.msg % tuple(self.args)
       
    21             return self.msg
       
    22         return ' '.join(str(arg) for arg in self.args)
       
    23 
       
    24 
       
    25 class ConfigurationError(CubicWebException):
       
    26     """a misconfiguration error"""
       
    27 
       
    28 class InternalError(CubicWebException):
       
    29     """base class for exceptions which should not occurs"""    
       
    30 
       
    31 class SecurityError(CubicWebException): 
       
    32     """base class for cubicweb server security exception"""
       
    33 
       
    34 class RepositoryError(CubicWebException):
       
    35     """base class for repository exceptions"""
       
    36 
       
    37 class SourceException(CubicWebException):
       
    38     """base class for source exceptions"""
       
    39 
       
    40 class CubicWebRuntimeError(CubicWebException):
       
    41     """base class for runtime exceptions"""
       
    42     
       
    43 # repository exceptions #######################################################
       
    44 
       
    45 class ConnectionError(RepositoryError):
       
    46     """raised when a bad connection id is given or when an attempt to establish
       
    47     a connection failed"""
       
    48 
       
    49 class AuthenticationError(ConnectionError):
       
    50     """raised when a bad connection id is given or when an attempt to establish
       
    51     a connection failed"""
       
    52 
       
    53 class BadConnectionId(ConnectionError):
       
    54     """raised when a bad connection id is given or when an attempt to establish
       
    55     a connection failed"""
       
    56     
       
    57 BadSessionId = BadConnectionId # XXX bw compat for pyro connections
       
    58 
       
    59 class UnknownEid(RepositoryError):
       
    60     """the eid is not defined in the system tables"""
       
    61     msg = 'No entity with eid %s in the repository'
       
    62 
       
    63 class ETypeNotSupportedBySources(RepositoryError, InternalError):
       
    64     """no source support an entity type"""
       
    65     msg = 'No source supports %r entity\'s type'
       
    66 
       
    67 class RTypeNotSupportedBySources(RepositoryError, InternalError):
       
    68     """no source support a relation type"""
       
    69     msg = 'No source supports %r relation\'s type'
       
    70 
       
    71     
       
    72 # security exceptions #########################################################
       
    73 
       
    74 class Unauthorized(SecurityError):
       
    75     """raised when a user tries to perform an action without sufficient
       
    76     credentials
       
    77     """
       
    78     msg = 'You are not allowed to perform this operation'
       
    79     msg1 = 'You are not allowed to perform %s operation on %s'
       
    80     var = None
       
    81     #def __init__(self, *args):
       
    82     #    self.args = args
       
    83         
       
    84     def __str__(self):
       
    85         try:
       
    86             if self.args and len(self.args) == 2:
       
    87                 return self.msg1 % self.args
       
    88             if self.args:
       
    89                 return ' '.join(self.args)
       
    90             return self.msg
       
    91         except Exception, ex:
       
    92             return str(ex)
       
    93     
       
    94 # source exceptions ###########################################################
       
    95 
       
    96 class EidNotInSource(SourceException):
       
    97     """trying to access an object with a particular eid from a particular
       
    98     source has failed
       
    99     """
       
   100     msg = 'No entity with eid %s in %s'
       
   101     
       
   102     
       
   103 # registry exceptions #########################################################
       
   104 
       
   105 class RegistryException(CubicWebException):
       
   106     """raised when an unregistered view is called"""
       
   107 
       
   108 class RegistryNotFound(RegistryException):
       
   109     """raised when an unknown registry is requested
       
   110 
       
   111     this is usually a programming/typo error...
       
   112     """
       
   113     
       
   114 class ObjectNotFound(RegistryException):
       
   115     """raised when an unregistered object is requested
       
   116 
       
   117     this may be a programming/typo or a misconfiguration error
       
   118     """
       
   119     
       
   120 # class ViewNotFound(ObjectNotFound):
       
   121 #     """raised when an unregistered view is called"""
       
   122     
       
   123 class NoSelectableObject(RegistryException):
       
   124     """some views with the given vid have been found but no
       
   125     one is applyable to the result set
       
   126     """
       
   127 
       
   128 class UnknownProperty(RegistryException):
       
   129     """property found in database but unknown in registry"""
       
   130 
       
   131 # query exception #############################################################
       
   132 
       
   133 class QueryError(CubicWebRuntimeError):
       
   134     """a query try to do something it shouldn't"""
       
   135 
       
   136 class NotAnEntity(CubicWebRuntimeError):
       
   137     """raised when get_entity is called for a column which doesn't contain
       
   138     a non final entity
       
   139     """
       
   140 
       
   141 # tools exceptions ############################################################
       
   142 
       
   143 class ExecutionError(Exception):
       
   144     """server execution control error (already started, not running...)"""
       
   145 
       
   146 # pylint: disable-msg=W0611
       
   147 from logilab.common.clcommands import BadCommandUsage 
       
   148