Show More
@@ -1,117 +1,117 b'' | |||||
1 | # RhodeCode VCSServer provides access to different vcs backends via network. |
|
1 | # RhodeCode VCSServer provides access to different vcs backends via network. | |
2 | # Copyright (C) 2014-2019 RhodeCode GmbH |
|
2 | # Copyright (C) 2014-2019 RhodeCode GmbH | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or modify |
|
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by |
|
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 3 of the License, or |
|
6 | # the Free Software Foundation; either version 3 of the License, or | |
7 | # (at your option) any later version. |
|
7 | # (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software Foundation, |
|
15 | # along with this program; if not, write to the Free Software Foundation, | |
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 | """ |
|
18 | """ | |
19 | Special exception handling over the wire. |
|
19 | Special exception handling over the wire. | |
20 |
|
20 | |||
21 | Since we cannot assume that our client is able to import our exception classes, |
|
21 | Since we cannot assume that our client is able to import our exception classes, | |
22 | this module provides a "wrapping" mechanism to raise plain exceptions |
|
22 | this module provides a "wrapping" mechanism to raise plain exceptions | |
23 | which contain an extra attribute `_vcs_kind` to allow a client to distinguish |
|
23 | which contain an extra attribute `_vcs_kind` to allow a client to distinguish | |
24 | different error conditions. |
|
24 | different error conditions. | |
25 | """ |
|
25 | """ | |
26 |
|
26 | |||
27 | from pyramid.httpexceptions import HTTPLocked, HTTPForbidden |
|
27 | from pyramid.httpexceptions import HTTPLocked, HTTPForbidden | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | def _make_exception(kind, org_exc, *args): |
|
30 | def _make_exception(kind, org_exc, *args): | |
31 | """ |
|
31 | """ | |
32 | Prepares a base `Exception` instance to be sent over the wire. |
|
32 | Prepares a base `Exception` instance to be sent over the wire. | |
33 |
|
33 | |||
34 | To give our caller a hint what this is about, it will attach an attribute |
|
34 | To give our caller a hint what this is about, it will attach an attribute | |
35 | `_vcs_kind` to the exception. |
|
35 | `_vcs_kind` to the exception. | |
36 | """ |
|
36 | """ | |
37 | exc = Exception(*args) |
|
37 | exc = Exception(*args) | |
38 | exc._vcs_kind = kind |
|
38 | exc._vcs_kind = kind | |
39 | exc._org_exc = org_exc |
|
39 | exc._org_exc = org_exc | |
40 | exc._org_exc_tb = '' |
|
40 | exc._org_exc_tb = getattr(org_exc, '_org_exc_tb', '') | |
41 | return exc |
|
41 | return exc | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | def AbortException(org_exc=None): |
|
44 | def AbortException(org_exc=None): | |
45 | def _make_exception_wrapper(*args): |
|
45 | def _make_exception_wrapper(*args): | |
46 | return _make_exception('abort', org_exc, *args) |
|
46 | return _make_exception('abort', org_exc, *args) | |
47 | return _make_exception_wrapper |
|
47 | return _make_exception_wrapper | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | def ArchiveException(org_exc=None): |
|
50 | def ArchiveException(org_exc=None): | |
51 | def _make_exception_wrapper(*args): |
|
51 | def _make_exception_wrapper(*args): | |
52 | return _make_exception('archive', org_exc, *args) |
|
52 | return _make_exception('archive', org_exc, *args) | |
53 | return _make_exception_wrapper |
|
53 | return _make_exception_wrapper | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | def LookupException(org_exc=None): |
|
56 | def LookupException(org_exc=None): | |
57 | def _make_exception_wrapper(*args): |
|
57 | def _make_exception_wrapper(*args): | |
58 | return _make_exception('lookup', org_exc, *args) |
|
58 | return _make_exception('lookup', org_exc, *args) | |
59 | return _make_exception_wrapper |
|
59 | return _make_exception_wrapper | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | def VcsException(org_exc=None): |
|
62 | def VcsException(org_exc=None): | |
63 | def _make_exception_wrapper(*args): |
|
63 | def _make_exception_wrapper(*args): | |
64 | return _make_exception('error', org_exc, *args) |
|
64 | return _make_exception('error', org_exc, *args) | |
65 | return _make_exception_wrapper |
|
65 | return _make_exception_wrapper | |
66 |
|
66 | |||
67 |
|
67 | |||
68 | def RepositoryLockedException(org_exc=None): |
|
68 | def RepositoryLockedException(org_exc=None): | |
69 | def _make_exception_wrapper(*args): |
|
69 | def _make_exception_wrapper(*args): | |
70 | return _make_exception('repo_locked', org_exc, *args) |
|
70 | return _make_exception('repo_locked', org_exc, *args) | |
71 | return _make_exception_wrapper |
|
71 | return _make_exception_wrapper | |
72 |
|
72 | |||
73 |
|
73 | |||
74 | def RepositoryBranchProtectedException(org_exc=None): |
|
74 | def RepositoryBranchProtectedException(org_exc=None): | |
75 | def _make_exception_wrapper(*args): |
|
75 | def _make_exception_wrapper(*args): | |
76 | return _make_exception('repo_branch_protected', org_exc, *args) |
|
76 | return _make_exception('repo_branch_protected', org_exc, *args) | |
77 | return _make_exception_wrapper |
|
77 | return _make_exception_wrapper | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | def RequirementException(org_exc=None): |
|
80 | def RequirementException(org_exc=None): | |
81 | def _make_exception_wrapper(*args): |
|
81 | def _make_exception_wrapper(*args): | |
82 | return _make_exception('requirement', org_exc, *args) |
|
82 | return _make_exception('requirement', org_exc, *args) | |
83 | return _make_exception_wrapper |
|
83 | return _make_exception_wrapper | |
84 |
|
84 | |||
85 |
|
85 | |||
86 | def UnhandledException(org_exc=None): |
|
86 | def UnhandledException(org_exc=None): | |
87 | def _make_exception_wrapper(*args): |
|
87 | def _make_exception_wrapper(*args): | |
88 | return _make_exception('unhandled', org_exc, *args) |
|
88 | return _make_exception('unhandled', org_exc, *args) | |
89 | return _make_exception_wrapper |
|
89 | return _make_exception_wrapper | |
90 |
|
90 | |||
91 |
|
91 | |||
92 | def URLError(org_exc=None): |
|
92 | def URLError(org_exc=None): | |
93 | def _make_exception_wrapper(*args): |
|
93 | def _make_exception_wrapper(*args): | |
94 | return _make_exception('url_error', org_exc, *args) |
|
94 | return _make_exception('url_error', org_exc, *args) | |
95 | return _make_exception_wrapper |
|
95 | return _make_exception_wrapper | |
96 |
|
96 | |||
97 |
|
97 | |||
98 | def SubrepoMergeException(org_exc=None): |
|
98 | def SubrepoMergeException(org_exc=None): | |
99 | def _make_exception_wrapper(*args): |
|
99 | def _make_exception_wrapper(*args): | |
100 | return _make_exception('subrepo_merge_error', org_exc, *args) |
|
100 | return _make_exception('subrepo_merge_error', org_exc, *args) | |
101 | return _make_exception_wrapper |
|
101 | return _make_exception_wrapper | |
102 |
|
102 | |||
103 |
|
103 | |||
104 | class HTTPRepoLocked(HTTPLocked): |
|
104 | class HTTPRepoLocked(HTTPLocked): | |
105 | """ |
|
105 | """ | |
106 | Subclass of HTTPLocked response that allows to set the title and status |
|
106 | Subclass of HTTPLocked response that allows to set the title and status | |
107 | code via constructor arguments. |
|
107 | code via constructor arguments. | |
108 | """ |
|
108 | """ | |
109 | def __init__(self, title, status_code=None, **kwargs): |
|
109 | def __init__(self, title, status_code=None, **kwargs): | |
110 | self.code = status_code or HTTPLocked.code |
|
110 | self.code = status_code or HTTPLocked.code | |
111 | self.title = title |
|
111 | self.title = title | |
112 | super(HTTPRepoLocked, self).__init__(**kwargs) |
|
112 | super(HTTPRepoLocked, self).__init__(**kwargs) | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | class HTTPRepoBranchProtected(HTTPForbidden): |
|
115 | class HTTPRepoBranchProtected(HTTPForbidden): | |
116 | def __init__(self, *args, **kwargs): |
|
116 | def __init__(self, *args, **kwargs): | |
117 | super(HTTPForbidden, self).__init__(*args, **kwargs) |
|
117 | super(HTTPForbidden, self).__init__(*args, **kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now