-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathhttp_response.py
More file actions
55 lines (35 loc) · 1.3 KB
/
http_response.py
File metadata and controls
55 lines (35 loc) · 1.3 KB
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
# This file was auto-generated by Fern from our API Definition.
from typing import Dict, Generic, TypeVar
import httpx
# Generic to represent the underlying type of the data wrapped by the HTTP response.
T = TypeVar("T")
class BaseHttpResponse:
"""Minimalist HTTP response wrapper that exposes response headers."""
_response: httpx.Response
def __init__(self, response: httpx.Response):
self._response = response
@property
def headers(self) -> Dict[str, str]:
return dict(self._response.headers)
class HttpResponse(Generic[T], BaseHttpResponse):
"""HTTP response wrapper that exposes response headers and data."""
_data: T
def __init__(self, response: httpx.Response, data: T):
super().__init__(response)
self._data = data
@property
def data(self) -> T:
return self._data
def close(self) -> None:
self._response.close()
class AsyncHttpResponse(Generic[T], BaseHttpResponse):
"""HTTP response wrapper that exposes response headers and data."""
_data: T
def __init__(self, response: httpx.Response, data: T):
super().__init__(response)
self._data = data
@property
def data(self) -> T:
return self._data
async def close(self) -> None:
await self._response.aclose()