|
1
|
|
|
|
|
|
|
|
|
|
2
|
|
|
class ConnectionError(Exception): |
|
|
|
|
|
|
3
|
|
|
def __init__(self, response, content=None, message=None): |
|
|
|
|
|
|
4
|
|
|
self.response = response |
|
5
|
|
|
self.content = content |
|
6
|
|
|
self.message = message |
|
7
|
|
|
|
|
8
|
|
|
def __str__(self): |
|
9
|
|
|
message = "Failed." |
|
10
|
|
|
if hasattr(self.response, 'status_code'): |
|
11
|
|
|
message += " Response status: %s." % self.response.status_code |
|
12
|
|
|
if hasattr(self.response, 'reason'): |
|
13
|
|
|
message += " Response message: %s." % self.response.reason |
|
14
|
|
|
if self.content is not None: |
|
15
|
|
|
message += " Error message: " + self.content |
|
16
|
|
|
return message |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
class Redirection(ConnectionError): |
|
20
|
|
|
"""3xx Redirection |
|
21
|
|
|
""" |
|
22
|
|
|
def __str__(self): |
|
23
|
|
|
message = super(Redirection, self).__str__() |
|
24
|
|
|
if self.response.get('Location'): |
|
25
|
|
|
message = "%s => %s" % (message, self.response.get('Location')) |
|
26
|
|
|
return message |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
class MissingParam(TypeError): |
|
|
|
|
|
|
30
|
|
|
pass |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
class MissingConfig(Exception): |
|
|
|
|
|
|
34
|
|
|
pass |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
class InvalidConfig(ValueError): |
|
|
|
|
|
|
38
|
|
|
pass |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
class ClientError(ConnectionError): |
|
42
|
|
|
"""4xx Client Error |
|
43
|
|
|
""" |
|
44
|
|
|
pass |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
class BadRequest(ClientError): |
|
48
|
|
|
"""400 Bad Request |
|
49
|
|
|
""" |
|
50
|
|
|
pass |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
class UnauthorizedAccess(ClientError): |
|
54
|
|
|
"""401 Unauthorized |
|
55
|
|
|
""" |
|
56
|
|
|
pass |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
class ForbiddenAccess(ClientError): |
|
60
|
|
|
"""403 Forbidden |
|
61
|
|
|
""" |
|
62
|
|
|
pass |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
class ResourceNotFound(ClientError): |
|
66
|
|
|
"""404 Not Found |
|
67
|
|
|
""" |
|
68
|
|
|
pass |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
class ResourceConflict(ClientError): |
|
72
|
|
|
"""409 Conflict |
|
73
|
|
|
""" |
|
74
|
|
|
pass |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
class ResourceGone(ClientError): |
|
78
|
|
|
"""410 Gone |
|
79
|
|
|
""" |
|
80
|
|
|
pass |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
class ResourceInvalid(ClientError): |
|
84
|
|
|
"""422 Invalid |
|
85
|
|
|
""" |
|
86
|
|
|
pass |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
class ServerError(ConnectionError): |
|
90
|
|
|
"""5xx Server Error |
|
91
|
|
|
""" |
|
92
|
|
|
pass |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
class MethodNotAllowed(ClientError): |
|
96
|
|
|
"""405 Method Not Allowed |
|
97
|
|
|
""" |
|
98
|
|
|
pass |
|
99
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.