author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 23 Jul 2009 15:13:21 +0200 | |
changeset 2452 | 868e0c75a57d |
parent 1977 | 606923dff11b |
child 2651 | 3ad936634d2a |
permissions | -rw-r--r-- |
0 | 1 |
"""Exceptions shared by different cubicweb packages. |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:copyright: 2001-2009 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 |
|
23 |
return ' '.join(str(arg) for arg in self.args) |
|
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 |
|
52 |
a connection failed""" |
|
53 |
||
54 |
class BadConnectionId(ConnectionError): |
|
55 |
"""raised when a bad connection id is given or when an attempt to establish |
|
56 |
a connection failed""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
57 |
|
0 | 58 |
BadSessionId = BadConnectionId # XXX bw compat for pyro connections |
59 |
||
60 |
class UnknownEid(RepositoryError): |
|
61 |
"""the eid is not defined in the system tables""" |
|
62 |
msg = 'No entity with eid %s in the repository' |
|
63 |
||
64 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
65 |
"""no source support an entity type""" |
|
66 |
msg = 'No source supports %r entity\'s type' |
|
67 |
||
68 |
class RTypeNotSupportedBySources(RepositoryError, InternalError): |
|
69 |
"""no source support a relation type""" |
|
70 |
msg = 'No source supports %r relation\'s type' |
|
71 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
72 |
|
0 | 73 |
# security exceptions ######################################################### |
74 |
||
75 |
class Unauthorized(SecurityError): |
|
76 |
"""raised when a user tries to perform an action without sufficient |
|
77 |
credentials |
|
78 |
""" |
|
79 |
msg = 'You are not allowed to perform this operation' |
|
80 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
81 |
var = None |
|
82 |
#def __init__(self, *args): |
|
83 |
# self.args = args |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
84 |
|
0 | 85 |
def __str__(self): |
86 |
try: |
|
87 |
if self.args and len(self.args) == 2: |
|
88 |
return self.msg1 % self.args |
|
89 |
if self.args: |
|
90 |
return ' '.join(self.args) |
|
91 |
return self.msg |
|
92 |
except Exception, ex: |
|
93 |
return str(ex) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
94 |
|
0 | 95 |
# source exceptions ########################################################### |
96 |
||
97 |
class EidNotInSource(SourceException): |
|
98 |
"""trying to access an object with a particular eid from a particular |
|
99 |
source has failed |
|
100 |
""" |
|
101 |
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
|
102 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
103 |
|
0 | 104 |
# registry exceptions ######################################################### |
105 |
||
106 |
class RegistryException(CubicWebException): |
|
107 |
"""raised when an unregistered view is called""" |
|
108 |
||
109 |
class RegistryNotFound(RegistryException): |
|
110 |
"""raised when an unknown registry is requested |
|
111 |
||
112 |
this is usually a programming/typo error... |
|
113 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
114 |
|
0 | 115 |
class ObjectNotFound(RegistryException): |
116 |
"""raised when an unregistered object is requested |
|
117 |
||
118 |
this may be a programming/typo or a misconfiguration error |
|
119 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
120 |
|
0 | 121 |
# class ViewNotFound(ObjectNotFound): |
122 |
# """raised when an unregistered view is called""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
123 |
|
0 | 124 |
class NoSelectableObject(RegistryException): |
125 |
"""some views with the given vid have been found but no |
|
126 |
one is applyable to the result set |
|
127 |
""" |
|
128 |
||
129 |
class UnknownProperty(RegistryException): |
|
130 |
"""property found in database but unknown in registry""" |
|
131 |
||
132 |
# query exception ############################################################# |
|
133 |
||
134 |
class QueryError(CubicWebRuntimeError): |
|
135 |
"""a query try to do something it shouldn't""" |
|
136 |
||
137 |
class NotAnEntity(CubicWebRuntimeError): |
|
138 |
"""raised when get_entity is called for a column which doesn't contain |
|
139 |
a non final entity |
|
140 |
""" |
|
141 |
||
142 |
# tools exceptions ############################################################ |
|
143 |
||
144 |
class ExecutionError(Exception): |
|
145 |
"""server execution control error (already started, not running...)""" |
|
146 |
||
147 |
# pylint: disable-msg=W0611 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
148 |
from logilab.common.clcommands import BadCommandUsage |
0 | 149 |