author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 17 Mar 2010 09:23:17 +0100 | |
changeset 4929 | 84684417beb9 |
parent 4911 | 898c35be5873 |
child 5032 | e3fa27fc0d9a |
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 |
|
48 |
a connection failed""" |
|
49 |
||
50 |
class AuthenticationError(ConnectionError): |
|
51 |
"""raised when a bad connection id is given or when an attempt to establish |
|
4911
898c35be5873
#750055: make it easier to change post logout url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4270
diff
changeset
|
52 |
a connection failed |
898c35be5873
#750055: make it easier to change post logout url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4270
diff
changeset
|
53 |
""" |
898c35be5873
#750055: make it easier to change post logout url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4270
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
self.__dict__.update(kwargs) |
0 | 57 |
|
58 |
class BadConnectionId(ConnectionError): |
|
59 |
"""raised when a bad connection id is given or when an attempt to establish |
|
60 |
a connection failed""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
61 |
|
0 | 62 |
BadSessionId = BadConnectionId # XXX bw compat for pyro connections |
63 |
||
64 |
class UnknownEid(RepositoryError): |
|
65 |
"""the eid is not defined in the system tables""" |
|
66 |
msg = 'No entity with eid %s in the repository' |
|
67 |
||
68 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
69 |
"""no source support an entity type""" |
|
70 |
msg = 'No source supports %r entity\'s type' |
|
71 |
||
3042
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
72 |
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
|
73 |
"""usually due to bad multisources configuration or rql query""" |
0 | 74 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
75 |
|
0 | 76 |
# security exceptions ######################################################### |
77 |
||
78 |
class Unauthorized(SecurityError): |
|
79 |
"""raised when a user tries to perform an action without sufficient |
|
80 |
credentials |
|
81 |
""" |
|
82 |
msg = 'You are not allowed to perform this operation' |
|
83 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
84 |
var = None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
85 |
|
0 | 86 |
def __str__(self): |
87 |
try: |
|
88 |
if self.args and len(self.args) == 2: |
|
89 |
return self.msg1 % self.args |
|
90 |
if self.args: |
|
91 |
return ' '.join(self.args) |
|
92 |
return self.msg |
|
93 |
except Exception, ex: |
|
94 |
return str(ex) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
95 |
|
0 | 96 |
# source exceptions ########################################################### |
97 |
||
98 |
class EidNotInSource(SourceException): |
|
99 |
"""trying to access an object with a particular eid from a particular |
|
100 |
source has failed |
|
101 |
""" |
|
102 |
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
|
103 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
104 |
|
0 | 105 |
# registry exceptions ######################################################### |
106 |
||
107 |
class RegistryException(CubicWebException): |
|
108 |
"""raised when an unregistered view is called""" |
|
109 |
||
110 |
class RegistryNotFound(RegistryException): |
|
111 |
"""raised when an unknown registry is requested |
|
112 |
||
113 |
this is usually a programming/typo error... |
|
114 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
115 |
|
0 | 116 |
class ObjectNotFound(RegistryException): |
117 |
"""raised when an unregistered object is requested |
|
118 |
||
119 |
this may be a programming/typo or a misconfiguration error |
|
120 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
121 |
|
0 | 122 |
class NoSelectableObject(RegistryException): |
123 |
"""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
|
124 |
one is applicable to the result set |
0 | 125 |
""" |
126 |
||
127 |
class UnknownProperty(RegistryException): |
|
128 |
"""property found in database but unknown in registry""" |
|
129 |
||
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
|
130 |
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
|
131 |
"""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
|
132 |
|
0 | 133 |
# query exception ############################################################# |
134 |
||
135 |
class QueryError(CubicWebRuntimeError): |
|
136 |
"""a query try to do something it shouldn't""" |
|
137 |
||
138 |
class NotAnEntity(CubicWebRuntimeError): |
|
139 |
"""raised when get_entity is called for a column which doesn't contain |
|
140 |
a non final entity |
|
141 |
""" |
|
142 |
||
143 |
# tools exceptions ############################################################ |
|
144 |
||
145 |
class ExecutionError(Exception): |
|
146 |
"""server execution control error (already started, not running...)""" |
|
147 |
||
148 |
# pylint: disable-msg=W0611 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
149 |
from logilab.common.clcommands import BadCommandUsage |