_exceptions.py
changeset 9375 8e88576787c3
parent 9347 bd841d6ae723
child 9467 ad66d7b3fd48
child 9517 3338b2205ea3
equal deleted inserted replaced
9374:1236d9058ad3 9375:8e88576787c3
     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):