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