author | Katia Saurfelt <katia.saurfelt@logilab.fr> |
Thu, 09 Feb 2012 18:11:30 +0100 | |
branch | stable |
changeset 8207 | c04676b16c59 |
parent 6491 | ee9a10b6620e |
child 8190 | 2a3c1b787688 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""Exceptions shared by different cubicweb packages. |
19 |
||
20 |
||
21 |
""" |
|
22 |
__docformat__ = "restructuredtext en" |
|
23 |
||
24 |
from yams import ValidationError |
|
25 |
||
26 |
# abstract exceptions ######################################################### |
|
27 |
||
28 |
class CubicWebException(Exception): |
|
29 |
"""base class for cubicweb server exception""" |
|
30 |
msg = "" |
|
31 |
def __str__(self): |
|
32 |
if self.msg: |
|
33 |
if self.args: |
|
34 |
return self.msg % tuple(self.args) |
|
35 |
return self.msg |
|
4270
189e4f5279e9
unicode(arg) else we may get some encoding exception
alex & cheb
parents:
4212
diff
changeset
|
36 |
return ' '.join(unicode(arg) for arg in self.args) |
0 | 37 |
|
38 |
||
39 |
class ConfigurationError(CubicWebException): |
|
40 |
"""a misconfiguration error""" |
|
41 |
||
42 |
class InternalError(CubicWebException): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
43 |
"""base class for exceptions which should not occurs""" |
0 | 44 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
45 |
class SecurityError(CubicWebException): |
0 | 46 |
"""base class for cubicweb server security exception""" |
47 |
||
48 |
class RepositoryError(CubicWebException): |
|
49 |
"""base class for repository exceptions""" |
|
50 |
||
51 |
class SourceException(CubicWebException): |
|
52 |
"""base class for source exceptions""" |
|
53 |
||
54 |
class CubicWebRuntimeError(CubicWebException): |
|
55 |
"""base class for runtime exceptions""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
56 |
|
0 | 57 |
# repository exceptions ####################################################### |
58 |
||
59 |
class ConnectionError(RepositoryError): |
|
60 |
"""raised when a bad connection id is given or when an attempt to establish |
|
5032 | 61 |
a connection failed |
62 |
""" |
|
0 | 63 |
|
64 |
class AuthenticationError(ConnectionError): |
|
5032 | 65 |
"""raised when when an attempt to establish a connection failed do to wrong |
66 |
connection information (login / password or other authentication token) |
|
4911
898c35be5873
#750055: make it easier to change post logout url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4270
diff
changeset
|
67 |
""" |
0 | 68 |
|
69 |
class BadConnectionId(ConnectionError): |
|
5032 | 70 |
"""raised when a bad connection id is given""" |
0 | 71 |
|
72 |
class UnknownEid(RepositoryError): |
|
73 |
"""the eid is not defined in the system tables""" |
|
74 |
msg = 'No entity with eid %s in the repository' |
|
75 |
||
76 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
77 |
"""no source support an entity type""" |
|
78 |
msg = 'No source supports %r entity\'s type' |
|
79 |
||
3042
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
80 |
class MultiSourcesError(RepositoryError, InternalError): |
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
81 |
"""usually due to bad multisources configuration or rql query""" |
0 | 82 |
|
6211
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
83 |
class UniqueTogetherError(RepositoryError): |
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
84 |
"""raised when a unique_together constraint caused an IntegrityError""" |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
85 |
|
0 | 86 |
# security exceptions ######################################################### |
87 |
||
88 |
class Unauthorized(SecurityError): |
|
89 |
"""raised when a user tries to perform an action without sufficient |
|
90 |
credentials |
|
91 |
""" |
|
92 |
msg = 'You are not allowed to perform this operation' |
|
93 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
94 |
var = None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
95 |
|
0 | 96 |
def __str__(self): |
97 |
try: |
|
98 |
if self.args and len(self.args) == 2: |
|
99 |
return self.msg1 % self.args |
|
100 |
if self.args: |
|
101 |
return ' '.join(self.args) |
|
102 |
return self.msg |
|
103 |
except Exception, ex: |
|
104 |
return str(ex) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
105 |
|
0 | 106 |
# source exceptions ########################################################### |
107 |
||
108 |
class EidNotInSource(SourceException): |
|
109 |
"""trying to access an object with a particular eid from a particular |
|
110 |
source has failed |
|
111 |
""" |
|
112 |
msg = 'No entity with eid %s in %s' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
113 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
114 |
|
0 | 115 |
# registry exceptions ######################################################### |
116 |
||
117 |
class RegistryException(CubicWebException): |
|
118 |
"""raised when an unregistered view is called""" |
|
119 |
||
120 |
class RegistryNotFound(RegistryException): |
|
121 |
"""raised when an unknown registry is requested |
|
122 |
||
123 |
this is usually a programming/typo error... |
|
124 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
125 |
|
0 | 126 |
class ObjectNotFound(RegistryException): |
127 |
"""raised when an unregistered object is requested |
|
128 |
||
129 |
this may be a programming/typo or a misconfiguration error |
|
130 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
131 |
|
0 | 132 |
class NoSelectableObject(RegistryException): |
6347
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
133 |
"""raised when no appobject is selectable for a given context.""" |
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
134 |
def __init__(self, args, kwargs, appobjects): |
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
135 |
self.args = args |
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
136 |
self.kwargs = kwargs |
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
137 |
self.appobjects = appobjects |
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
138 |
|
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
139 |
def __str__(self): |
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
140 |
return ('args: %s, kwargs: %s\ncandidates: %s' |
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
141 |
% (self.args, self.kwargs.keys(), self.appobjects)) |
ef47a2100c66
exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6211
diff
changeset
|
142 |
|
0 | 143 |
|
144 |
class UnknownProperty(RegistryException): |
|
145 |
"""property found in database but unknown in registry""" |
|
146 |
||
147 |
# query exception ############################################################# |
|
148 |
||
149 |
class QueryError(CubicWebRuntimeError): |
|
150 |
"""a query try to do something it shouldn't""" |
|
151 |
||
152 |
class NotAnEntity(CubicWebRuntimeError): |
|
153 |
"""raised when get_entity is called for a column which doesn't contain |
|
154 |
a non final entity |
|
155 |
""" |
|
156 |
||
157 |
# tools exceptions ############################################################ |
|
158 |
||
159 |
class ExecutionError(Exception): |
|
160 |
"""server execution control error (already started, not running...)""" |
|
161 |
||
6491
ee9a10b6620e
pylint option update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6347
diff
changeset
|
162 |
# pylint: disable=W0611 |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
163 |
from logilab.common.clcommands import BadCommandUsage |