author | Sylvain <syt@logilab.fr> |
Thu, 14 May 2009 14:51:52 +0200 | |
changeset 1819 | 7d3e8adcd559 |
parent 1802 | d628defebc17 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
"""Exceptions shared by different cubicweb packages. |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
1155 | 5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 |
""" |
|
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from yams import ValidationError |
|
11 |
||
12 |
# abstract exceptions ######################################################### |
|
13 |
||
14 |
class CubicWebException(Exception): |
|
15 |
"""base class for cubicweb server exception""" |
|
16 |
msg = "" |
|
17 |
def __str__(self): |
|
18 |
if self.msg: |
|
19 |
if self.args: |
|
20 |
return self.msg % tuple(self.args) |
|
21 |
return self.msg |
|
22 |
return ' '.join(str(arg) for arg in self.args) |
|
23 |
||
24 |
||
25 |
class ConfigurationError(CubicWebException): |
|
26 |
"""a misconfiguration error""" |
|
27 |
||
28 |
class InternalError(CubicWebException): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
29 |
"""base class for exceptions which should not occurs""" |
0 | 30 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
31 |
class SecurityError(CubicWebException): |
0 | 32 |
"""base class for cubicweb server security exception""" |
33 |
||
34 |
class RepositoryError(CubicWebException): |
|
35 |
"""base class for repository exceptions""" |
|
36 |
||
37 |
class SourceException(CubicWebException): |
|
38 |
"""base class for source exceptions""" |
|
39 |
||
40 |
class CubicWebRuntimeError(CubicWebException): |
|
41 |
"""base class for runtime exceptions""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
42 |
|
0 | 43 |
# repository exceptions ####################################################### |
44 |
||
45 |
class ConnectionError(RepositoryError): |
|
46 |
"""raised when a bad connection id is given or when an attempt to establish |
|
47 |
a connection failed""" |
|
48 |
||
49 |
class AuthenticationError(ConnectionError): |
|
50 |
"""raised when a bad connection id is given or when an attempt to establish |
|
51 |
a connection failed""" |
|
52 |
||
53 |
class BadConnectionId(ConnectionError): |
|
54 |
"""raised when a bad connection id is given or when an attempt to establish |
|
55 |
a connection failed""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
56 |
|
0 | 57 |
BadSessionId = BadConnectionId # XXX bw compat for pyro connections |
58 |
||
59 |
class UnknownEid(RepositoryError): |
|
60 |
"""the eid is not defined in the system tables""" |
|
61 |
msg = 'No entity with eid %s in the repository' |
|
62 |
||
63 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
64 |
"""no source support an entity type""" |
|
65 |
msg = 'No source supports %r entity\'s type' |
|
66 |
||
67 |
class RTypeNotSupportedBySources(RepositoryError, InternalError): |
|
68 |
"""no source support a relation type""" |
|
69 |
msg = 'No source supports %r relation\'s type' |
|
70 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
71 |
|
0 | 72 |
# security exceptions ######################################################### |
73 |
||
74 |
class Unauthorized(SecurityError): |
|
75 |
"""raised when a user tries to perform an action without sufficient |
|
76 |
credentials |
|
77 |
""" |
|
78 |
msg = 'You are not allowed to perform this operation' |
|
79 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
80 |
var = None |
|
81 |
#def __init__(self, *args): |
|
82 |
# self.args = args |
|
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 ViewNotFound(ObjectNotFound): |
121 |
# """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
|
122 |
|
0 | 123 |
class NoSelectableObject(RegistryException): |
124 |
"""some views with the given vid have been found but no |
|
125 |
one is applyable to the result set |
|
126 |
""" |
|
127 |
||
128 |
class UnknownProperty(RegistryException): |
|
129 |
"""property found in database but unknown in registry""" |
|
130 |
||
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 |
0 | 148 |