-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathresponse.py
77 lines (69 loc) · 2.11 KB
/
response.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
__all__ = ["Response"]
from typing import Any, MutableMapping, Optional
class Response:
"""HTTP response.
:param method: HTTP method in lowercase (e.g. "post").
:type method: str
:param url: API URL.
:type url: str
:param headers: Response headers.
:type headers: MutableMapping
:param status_code: Response status code.
:type status_code: int
:param status_text: Response status text.
:type status_text: str
:param raw_body: Raw response body.
:type raw_body: str
:ivar method: HTTP method in lowercase (e.g. "post").
:vartype method: str
:ivar url: API URL.
:vartype url: str
:ivar headers: Response headers.
:vartype headers: MutableMapping
:ivar status_code: Response status code.
:vartype status_code: int
:ivar status_text: Response status text.
:vartype status_text: str
:ivar raw_body: Raw response body.
:vartype raw_body: str
:ivar body: JSON-deserialized response body.
:vartype body: str | bool | int | float | list | dict | None
:ivar error_code: Error code from ArangoDB server.
:vartype error_code: int
:ivar error_message: Error message from ArangoDB server.
:vartype error_message: str
:ivar is_success: True if response status code was 2XX.
:vartype is_success: bool
"""
__slots__ = (
"method",
"url",
"headers",
"status_code",
"status_text",
"body",
"raw_body",
"error_code",
"error_message",
"is_success",
)
def __init__(
self,
method: str,
url: str,
headers: MutableMapping[str, str],
status_code: int,
status_text: str,
raw_body: str,
) -> None:
self.method = method.lower()
self.url = url
self.headers = headers
self.status_code = status_code
self.status_text = status_text
self.raw_body = raw_body
# Populated later
self.body: Any = None
self.error_code: Optional[int] = None
self.error_message: Optional[str] = None
self.is_success: Optional[bool] = None