author | Laurent Peuch <cortex@worlddomination.be> |
Thu, 23 May 2019 00:33:04 +0200 | |
changeset 12746 | 5c432a7fc442 |
parent 12608 | 6b2a9f288956 |
permissions | -rw-r--r-- |
6491
ee9a10b6620e
pylint option update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
1 |
# pylint: disable=W0401,W0614 |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
2 |
# 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:
5389
diff
changeset
|
3 |
# 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:
5389
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
5 |
# 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:
5389
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
7 |
# 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:
5389
diff
changeset
|
8 |
# 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:
5389
diff
changeset
|
9 |
# 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:
5389
diff
changeset
|
10 |
# 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:
5389
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# 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:
5389
diff
changeset
|
13 |
# 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:
5389
diff
changeset
|
14 |
# 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:
5389
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
17 |
# 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:
5389
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
19 |
"""exceptions used in the core of the CubicWeb web application""" |
0 | 20 |
|
12567
26744ad37953
Drop python2 support
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
21 |
import http.client as http_client |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
22 |
|
0 | 23 |
from cubicweb._exceptions import * |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
24 |
from cubicweb.utils import json_dumps |
0 | 25 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
26 |
|
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
27 |
class DirectResponse(Exception): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
28 |
"""Used to supply a twitted HTTP Response directly""" |
12607
3bf9002de48e
[autopep8] E301 - Add missing blank line
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
29 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
30 |
def __init__(self, response): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
31 |
self.response = response |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
32 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
33 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
34 |
class InvalidSession(CubicWebException): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
35 |
"""raised when a session id is found but associated session is not found or |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
36 |
invalid""" |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
37 |
|
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
38 |
# Publish related exception |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
39 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
40 |
|
0 | 41 |
class PublishException(CubicWebException): |
42 |
"""base class for publishing related exception""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
320
diff
changeset
|
43 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
44 |
def __init__(self, *args, **kwargs): |
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9984
diff
changeset
|
45 |
self.status = kwargs.pop('status', http_client.OK) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
46 |
super(PublishException, self).__init__(*args, **kwargs) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
47 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
48 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
49 |
class LogOut(PublishException): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
50 |
"""raised to ask for deauthentication of a logged in user""" |
12607
3bf9002de48e
[autopep8] E301 - Add missing blank line
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
51 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
52 |
def __init__(self, url=None): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
53 |
super(LogOut, self).__init__() |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
54 |
self.url = url |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
55 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
56 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
57 |
class Redirect(PublishException): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
58 |
"""raised to redirect the http request""" |
12607
3bf9002de48e
[autopep8] E301 - Add missing blank line
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
59 |
|
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9984
diff
changeset
|
60 |
def __init__(self, location, status=http_client.SEE_OTHER): |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
61 |
super(Redirect, self).__init__(status=status) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
62 |
self.location = location |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
63 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
64 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
65 |
class StatusResponse(PublishException): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
66 |
|
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
67 |
def __init__(self, status, content=''): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
68 |
super(StatusResponse, self).__init__(status=status) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
69 |
self.content = content |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
70 |
|
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
71 |
def __repr__(self): |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
72 |
return '%s(%r, %r)' % (self.__class__.__name__, self.status, self.content) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
73 |
|
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
74 |
# Publish related error |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
75 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
76 |
|
0 | 77 |
class RequestError(PublishException): |
78 |
"""raised when a request can't be served because of a bad input""" |
|
79 |
||
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
80 |
def __init__(self, *args, **kwargs): |
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9984
diff
changeset
|
81 |
kwargs.setdefault('status', http_client.BAD_REQUEST) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
82 |
super(RequestError, self).__init__(*args, **kwargs) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
83 |
|
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
84 |
|
0 | 85 |
class NothingToEdit(RequestError): |
86 |
"""raised when an edit request doesn't specify any eid to edit""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
320
diff
changeset
|
87 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
88 |
def __init__(self, *args, **kwargs): |
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9984
diff
changeset
|
89 |
kwargs.setdefault('status', http_client.BAD_REQUEST) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
90 |
super(NothingToEdit, self).__init__(*args, **kwargs) |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
91 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
92 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
93 |
class ProcessFormError(RequestError): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
94 |
"""raised when posted data can't be processed by the corresponding field |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
95 |
""" |
12607
3bf9002de48e
[autopep8] E301 - Add missing blank line
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
96 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
97 |
def __init__(self, *args, **kwargs): |
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9984
diff
changeset
|
98 |
kwargs.setdefault('status', http_client.BAD_REQUEST) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
99 |
super(ProcessFormError, self).__init__(*args, **kwargs) |
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
100 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
101 |
|
0 | 102 |
class NotFound(RequestError): |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
103 |
"""raised when something was not found. In most case, |
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
104 |
a 404 error should be returned""" |
0 | 105 |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
106 |
def __init__(self, *args, **kwargs): |
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9984
diff
changeset
|
107 |
kwargs.setdefault('status', http_client.NOT_FOUND) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7384
diff
changeset
|
108 |
super(NotFound, self).__init__(*args, **kwargs) |
0 | 109 |
|
12608
6b2a9f288956
[autopep8] E302 - Add missing 2 blank lines
Laurent Peuch <cortex@worlddomination.be>
parents:
12607
diff
changeset
|
110 |
|
0 | 111 |
class RemoteCallFailed(RequestError): |
112 |
"""raised when a json remote call fails |
|
113 |
""" |
|
12607
3bf9002de48e
[autopep8] E301 - Add missing blank line
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
114 |
|
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9984
diff
changeset
|
115 |
def __init__(self, reason='', status=http_client.INTERNAL_SERVER_ERROR): |
9921
8227358aa983
[web] Return useful error messages when exceptions arise in ajax controllers (closes #3932503)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8312
diff
changeset
|
116 |
super(RemoteCallFailed, self).__init__(reason, status=status) |
0 | 117 |
self.reason = reason |
118 |
||
119 |
def dumps(self): |
|
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
120 |
return json_dumps({'reason': self.reason}) |