_exceptions.py
branchstable
changeset 9542 79b9bf88be28
parent 9517 3338b2205ea3
child 9543 39f981482e34
equal deleted inserted replaced
9540:43b4895a150f 9542:79b9bf88be28
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Exceptions shared by different cubicweb packages."""
    18 """Exceptions shared by different cubicweb packages."""
    19 
    19 
    20 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
       
    21 
       
    22 from warnings import warn
       
    23 
       
    24 from logilab.common.decorators import cachedproperty
    21 
    25 
    22 from yams import ValidationError as ValidationError
    26 from yams import ValidationError as ValidationError
    23 
    27 
    24 # abstract exceptions #########################################################
    28 # abstract exceptions #########################################################
    25 
    29 
    79 class MultiSourcesError(RepositoryError, InternalError):
    83 class MultiSourcesError(RepositoryError, InternalError):
    80     """usually due to bad multisources configuration or rql query"""
    84     """usually due to bad multisources configuration or rql query"""
    81 
    85 
    82 class UniqueTogetherError(RepositoryError):
    86 class UniqueTogetherError(RepositoryError):
    83     """raised when a unique_together constraint caused an IntegrityError"""
    87     """raised when a unique_together constraint caused an IntegrityError"""
       
    88     def __init__(self, session, **kwargs):
       
    89         self.session = session
       
    90         assert 'rtypes' in kwargs or 'cstrname' in kwargs
       
    91         self.kwargs = kwargs
       
    92 
       
    93     @cachedproperty
       
    94     def rtypes(self):
       
    95         if 'rtypes' in self.kwargs:
       
    96             return self.kwargs['rtypes']
       
    97         cstrname = unicode(self.kwargs['cstrname'])
       
    98         cstr = self.session.find('CWUniqueTogetherConstraint', name=cstrname).one()
       
    99         return sorted(rtype.name for rtype in cstr.relations)
       
   100 
       
   101     @cachedproperty
       
   102     def args(self):
       
   103         warn('[3.18] UniqueTogetherError.args is deprecated, just use '
       
   104              'the .rtypes accessor.',
       
   105              DeprecationWarning)
       
   106         # the first argument, etype, is never used and was never garanteed anyway
       
   107         return None, self.rtypes
    84 
   108 
    85 
   109 
    86 # security exceptions #########################################################
   110 # security exceptions #########################################################
    87 
   111 
    88 class Unauthorized(SecurityError):
   112 class Unauthorized(SecurityError):
   132 class NotAnEntity(CubicWebRuntimeError):
   156 class NotAnEntity(CubicWebRuntimeError):
   133     """raised when get_entity is called for a column which doesn't contain
   157     """raised when get_entity is called for a column which doesn't contain
   134     a non final entity
   158     a non final entity
   135     """
   159     """
   136 
   160 
       
   161 class MultipleResultsError(CubicWebRuntimeError):
       
   162     """raised when ResultSet.one() is called on a resultset with multiple rows
       
   163     of multiple columns.
       
   164     """
       
   165 
       
   166 class NoResultError(CubicWebRuntimeError):
       
   167     """raised when no result is found but at least one is expected.
       
   168     """
       
   169 
   137 class UndoTransactionException(QueryError):
   170 class UndoTransactionException(QueryError):
   138     """Raised when undoing a transaction could not be performed completely.
   171     """Raised when undoing a transaction could not be performed completely.
   139 
   172 
   140     Note that :
   173     Note that :
   141       1) the partial undo operation might be acceptable
   174       1) the partial undo operation might be acceptable
   152 
   185 
   153     :type txuuix: int
   186     :type txuuix: int
   154     :param txuuid: Unique identifier of the partialy undone transaction
   187     :param txuuid: Unique identifier of the partialy undone transaction
   155 
   188 
   156     :type errors: list
   189     :type errors: list
   157     :param errors: List of errors occured during undoing
   190     :param errors: List of errors occurred during undoing
   158     """
   191     """
   159     msg = u"The following error(s) occured while undoing transaction #%d : %s"
   192     msg = u"The following error(s) occurred while undoing transaction #%d : %s"
   160 
   193 
   161     def __init__(self, txuuid, errors):
   194     def __init__(self, txuuid, errors):
   162         super(UndoTransactionException, self).__init__(txuuid, errors)
   195         super(UndoTransactionException, self).__init__(txuuid, errors)
   163         self.txuuid = txuuid
   196         self.txuuid = txuuid
   164         self.errors = errors
   197         self.errors = errors