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