author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 30 Mar 2010 13:28:19 +0200 | |
branch | stable |
changeset 5078 | ea66c4aabb47 |
parent 5032 | e3fa27fc0d9a |
child 5223 | 6abd6e3599f4 |
child 5273 | c4caef6f09c9 |
permissions | -rw-r--r-- |
0 | 1 |
"""Exceptions shared by different cubicweb packages. |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3162
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
||
11 |
from yams import ValidationError |
|
12 |
||
13 |
# abstract exceptions ######################################################### |
|
14 |
||
15 |
class CubicWebException(Exception): |
|
16 |
"""base class for cubicweb server exception""" |
|
17 |
msg = "" |
|
18 |
def __str__(self): |
|
19 |
if self.msg: |
|
20 |
if self.args: |
|
21 |
return self.msg % tuple(self.args) |
|
22 |
return self.msg |
|
4270
189e4f5279e9
unicode(arg) else we may get some encoding exception
alex & cheb
parents:
4212
diff
changeset
|
23 |
return ' '.join(unicode(arg) for arg in self.args) |
0 | 24 |
|
25 |
||
26 |
class ConfigurationError(CubicWebException): |
|
27 |
"""a misconfiguration error""" |
|
28 |
||
29 |
class InternalError(CubicWebException): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
30 |
"""base class for exceptions which should not occurs""" |
0 | 31 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
32 |
class SecurityError(CubicWebException): |
0 | 33 |
"""base class for cubicweb server security exception""" |
34 |
||
35 |
class RepositoryError(CubicWebException): |
|
36 |
"""base class for repository exceptions""" |
|
37 |
||
38 |
class SourceException(CubicWebException): |
|
39 |
"""base class for source exceptions""" |
|
40 |
||
41 |
class CubicWebRuntimeError(CubicWebException): |
|
42 |
"""base class for runtime exceptions""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
43 |
|
0 | 44 |
# repository exceptions ####################################################### |
45 |
||
46 |
class ConnectionError(RepositoryError): |
|
47 |
"""raised when a bad connection id is given or when an attempt to establish |
|
5032 | 48 |
a connection failed |
49 |
""" |
|
0 | 50 |
|
51 |
class AuthenticationError(ConnectionError): |
|
5032 | 52 |
"""raised when when an attempt to establish a connection failed do to wrong |
53 |
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
|
54 |
""" |
898c35be5873
#750055: make it easier to change post logout url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4270
diff
changeset
|
55 |
def __init__(self, *args, **kwargs): |
898c35be5873
#750055: make it easier to change post logout url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4270
diff
changeset
|
56 |
super(AuthenticationError, self).__init__(*args) |
898c35be5873
#750055: make it easier to change post logout url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4270
diff
changeset
|
57 |
self.__dict__.update(kwargs) |
0 | 58 |
|
59 |
class BadConnectionId(ConnectionError): |
|
5032 | 60 |
"""raised when a bad connection id is given""" |
0 | 61 |
|
62 |
class UnknownEid(RepositoryError): |
|
63 |
"""the eid is not defined in the system tables""" |
|
64 |
msg = 'No entity with eid %s in the repository' |
|
65 |
||
66 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
67 |
"""no source support an entity type""" |
|
68 |
msg = 'No source supports %r entity\'s type' |
|
69 |
||
3042
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
70 |
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
|
71 |
"""usually due to bad multisources configuration or rql query""" |
0 | 72 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
73 |
|
0 | 74 |
# security exceptions ######################################################### |
75 |
||
76 |
class Unauthorized(SecurityError): |
|
77 |
"""raised when a user tries to perform an action without sufficient |
|
78 |
credentials |
|
79 |
""" |
|
80 |
msg = 'You are not allowed to perform this operation' |
|
81 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
82 |
var = None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
83 |
|
0 | 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) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
93 |
|
0 | 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' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
101 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
102 |
|
0 | 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 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
113 |
|
0 | 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 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
119 |
|
0 | 120 |
class NoSelectableObject(RegistryException): |
121 |
"""some views with the given vid have been found but no |
|
3144
a5deac822a13
Bugfix: message was not written in english
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2850
diff
changeset
|
122 |
one is applicable to the result set |
0 | 123 |
""" |
124 |
||
125 |
class UnknownProperty(RegistryException): |
|
126 |
"""property found in database but unknown in registry""" |
|
127 |
||
2651
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
128 |
class RegistryOutOfDate(RegistryException): |
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
129 |
"""raised when a source file modification is detected""" |
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
130 |
|
0 | 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 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
147 |
from logilab.common.clcommands import BadCommandUsage |