Show More
@@ -1,68 +1,70 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-2016 RodeCode GmbH |
|
2 | # Copyright (C) 2014-2016 RodeCode 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 | import functools |
|
27 | import functools | |
28 | from pyramid.httpexceptions import HTTPLocked |
|
28 | from pyramid.httpexceptions import HTTPLocked | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | def _make_exception(kind, *args): |
|
31 | def _make_exception(kind, *args): | |
32 | """ |
|
32 | """ | |
33 | Prepares a base `Exception` instance to be sent over the wire. |
|
33 | Prepares a base `Exception` instance to be sent over the wire. | |
34 |
|
34 | |||
35 | To give our caller a hint what this is about, it will attach an attribute |
|
35 | To give our caller a hint what this is about, it will attach an attribute | |
36 | `_vcs_kind` to the exception. |
|
36 | `_vcs_kind` to the exception. | |
37 | """ |
|
37 | """ | |
38 | exc = Exception(*args) |
|
38 | exc = Exception(*args) | |
39 | exc._vcs_kind = kind |
|
39 | exc._vcs_kind = kind | |
40 | return exc |
|
40 | return exc | |
41 |
|
41 | |||
42 |
|
42 | |||
43 | AbortException = functools.partial(_make_exception, 'abort') |
|
43 | AbortException = functools.partial(_make_exception, 'abort') | |
44 |
|
44 | |||
45 | ArchiveException = functools.partial(_make_exception, 'archive') |
|
45 | ArchiveException = functools.partial(_make_exception, 'archive') | |
46 |
|
46 | |||
47 | LookupException = functools.partial(_make_exception, 'lookup') |
|
47 | LookupException = functools.partial(_make_exception, 'lookup') | |
48 |
|
48 | |||
49 | VcsException = functools.partial(_make_exception, 'error') |
|
49 | VcsException = functools.partial(_make_exception, 'error') | |
50 |
|
50 | |||
51 | RepositoryLockedException = functools.partial(_make_exception, 'repo_locked') |
|
51 | RepositoryLockedException = functools.partial(_make_exception, 'repo_locked') | |
52 |
|
52 | |||
53 | RequirementException = functools.partial(_make_exception, 'requirement') |
|
53 | RequirementException = functools.partial(_make_exception, 'requirement') | |
54 |
|
54 | |||
55 | UnhandledException = functools.partial(_make_exception, 'unhandled') |
|
55 | UnhandledException = functools.partial(_make_exception, 'unhandled') | |
56 |
|
56 | |||
57 | URLError = functools.partial(_make_exception, 'url_error') |
|
57 | URLError = functools.partial(_make_exception, 'url_error') | |
58 |
|
58 | |||
|
59 | SubrepoMergeException = functools.partial(_make_exception, 'subrepo_merge_error') | |||
|
60 | ||||
59 |
|
61 | |||
60 | class HTTPRepoLocked(HTTPLocked): |
|
62 | class HTTPRepoLocked(HTTPLocked): | |
61 | """ |
|
63 | """ | |
62 | Subclass of HTTPLocked response that allows to set the title and status |
|
64 | Subclass of HTTPLocked response that allows to set the title and status | |
63 | code via constructor arguments. |
|
65 | code via constructor arguments. | |
64 | """ |
|
66 | """ | |
65 | def __init__(self, title, status_code=None, **kwargs): |
|
67 | def __init__(self, title, status_code=None, **kwargs): | |
66 | self.code = status_code or HTTPLocked.code |
|
68 | self.code = status_code or HTTPLocked.code | |
67 | self.title = title |
|
69 | self.title = title | |
68 | super(HTTPRepoLocked, self).__init__(**kwargs) |
|
70 | super(HTTPRepoLocked, self).__init__(**kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now