author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 23 Jan 2012 13:25:02 +0100 | |
changeset 8190 | 2a3c1b787688 |
parent 6491 | ee9a10b6620e |
child 8265 | 9747ab9230ad |
permissions | -rw-r--r-- |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
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
|
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/>. |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
18 |
"""Exceptions shared by different cubicweb packages.""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
22 |
from yams import ValidationError |
|
23 |
||
24 |
# abstract exceptions ######################################################### |
|
25 |
||
26 |
class CubicWebException(Exception): |
|
27 |
"""base class for cubicweb server exception""" |
|
28 |
msg = "" |
|
29 |
def __str__(self): |
|
30 |
if self.msg: |
|
31 |
if self.args: |
|
32 |
return self.msg % tuple(self.args) |
|
33 |
return self.msg |
|
4270
189e4f5279e9
unicode(arg) else we may get some encoding exception
alex & cheb
parents:
4212
diff
changeset
|
34 |
return ' '.join(unicode(arg) for arg in self.args) |
0 | 35 |
|
36 |
||
37 |
class ConfigurationError(CubicWebException): |
|
38 |
"""a misconfiguration error""" |
|
39 |
||
40 |
class InternalError(CubicWebException): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
41 |
"""base class for exceptions which should not occurs""" |
0 | 42 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
43 |
class SecurityError(CubicWebException): |
0 | 44 |
"""base class for cubicweb server security exception""" |
45 |
||
46 |
class RepositoryError(CubicWebException): |
|
47 |
"""base class for repository exceptions""" |
|
48 |
||
49 |
class SourceException(CubicWebException): |
|
50 |
"""base class for source exceptions""" |
|
51 |
||
52 |
class CubicWebRuntimeError(CubicWebException): |
|
53 |
"""base class for runtime exceptions""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
54 |
|
0 | 55 |
# repository exceptions ####################################################### |
56 |
||
57 |
class ConnectionError(RepositoryError): |
|
58 |
"""raised when a bad connection id is given or when an attempt to establish |
|
5032 | 59 |
a connection failed |
60 |
""" |
|
0 | 61 |
|
62 |
class AuthenticationError(ConnectionError): |
|
5032 | 63 |
"""raised when when an attempt to establish a connection failed do to wrong |
64 |
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
|
65 |
""" |
0 | 66 |
|
67 |
class BadConnectionId(ConnectionError): |
|
5032 | 68 |
"""raised when a bad connection id is given""" |
0 | 69 |
|
70 |
class UnknownEid(RepositoryError): |
|
71 |
"""the eid is not defined in the system tables""" |
|
72 |
msg = 'No entity with eid %s in the repository' |
|
73 |
||
74 |
class ETypeNotSupportedBySources(RepositoryError, InternalError): |
|
75 |
"""no source support an entity type""" |
|
76 |
msg = 'No source supports %r entity\'s type' |
|
77 |
||
3042
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2850
diff
changeset
|
78 |
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
|
79 |
"""usually due to bad multisources configuration or rql query""" |
0 | 80 |
|
6211
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
81 |
class UniqueTogetherError(RepositoryError): |
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
82 |
"""raised when a unique_together constraint caused an IntegrityError""" |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
83 |
|
0 | 84 |
# security exceptions ######################################################### |
85 |
||
86 |
class Unauthorized(SecurityError): |
|
87 |
"""raised when a user tries to perform an action without sufficient |
|
88 |
credentials |
|
89 |
""" |
|
90 |
msg = 'You are not allowed to perform this operation' |
|
91 |
msg1 = 'You are not allowed to perform %s operation on %s' |
|
92 |
var = None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
93 |
|
0 | 94 |
def __str__(self): |
95 |
try: |
|
96 |
if self.args and len(self.args) == 2: |
|
97 |
return self.msg1 % self.args |
|
98 |
if self.args: |
|
99 |
return ' '.join(self.args) |
|
100 |
return self.msg |
|
101 |
except Exception, ex: |
|
102 |
return str(ex) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
103 |
|
0 | 104 |
# source exceptions ########################################################### |
105 |
||
106 |
class EidNotInSource(SourceException): |
|
107 |
"""trying to access an object with a particular eid from a particular |
|
108 |
source has failed |
|
109 |
""" |
|
110 |
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
|
111 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
112 |
|
0 | 113 |
# registry exceptions ######################################################### |
114 |
||
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
115 |
# pre 3.15 bw compat |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
116 |
from logilab.common.registry import RegistryException, ObjectNotFound, NoSelectableObject |
0 | 117 |
|
118 |
class UnknownProperty(RegistryException): |
|
119 |
"""property found in database but unknown in registry""" |
|
120 |
||
121 |
# query exception ############################################################# |
|
122 |
||
123 |
class QueryError(CubicWebRuntimeError): |
|
124 |
"""a query try to do something it shouldn't""" |
|
125 |
||
126 |
class NotAnEntity(CubicWebRuntimeError): |
|
127 |
"""raised when get_entity is called for a column which doesn't contain |
|
128 |
a non final entity |
|
129 |
""" |
|
130 |
||
131 |
# tools exceptions ############################################################ |
|
132 |
||
133 |
class ExecutionError(Exception): |
|
134 |
"""server execution control error (already started, not running...)""" |
|
135 |
||
6491
ee9a10b6620e
pylint option update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6347
diff
changeset
|
136 |
# pylint: disable=W0611 |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1155
diff
changeset
|
137 |
from logilab.common.clcommands import BadCommandUsage |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
138 |