internetdata 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- internetdata/__init__.py +49 -0
- internetdata/_core.py +287 -0
- internetdata/_generated/__init__.py +8 -0
- internetdata/_generated/api/__init__.py +1 -0
- internetdata/_generated/api/database_v_2/__init__.py +1 -0
- internetdata/_generated/api/database_v_2/database_checksum_v2.py +203 -0
- internetdata/_generated/api/database_v_2/database_metadata_v2.py +205 -0
- internetdata/_generated/api/database_v_2/download_database_v2.py +213 -0
- internetdata/_generated/api/database_v_2/list_databases.py +162 -0
- internetdata/_generated/api/database_v_2/list_downloads.py +178 -0
- internetdata/_generated/client.py +272 -0
- internetdata/_generated/errors.py +16 -0
- internetdata/_generated/models/__init__.py +53 -0
- internetdata/_generated/models/database.py +233 -0
- internetdata/_generated/models/database_checksum_v2_format.py +9 -0
- internetdata/_generated/models/database_checksum_v2_response_200.py +85 -0
- internetdata/_generated/models/database_checksum_v2_response_200_format.py +9 -0
- internetdata/_generated/models/database_metadata.py +132 -0
- internetdata/_generated/models/database_metadata_column.py +80 -0
- internetdata/_generated/models/database_metadata_sample.py +78 -0
- internetdata/_generated/models/database_metadata_sample_additional_property_item.py +45 -0
- internetdata/_generated/models/database_metadata_schema.py +72 -0
- internetdata/_generated/models/database_metadata_size.py +47 -0
- internetdata/_generated/models/database_redistribution_type_1.py +10 -0
- internetdata/_generated/models/database_redistribution_type_2_type_1.py +10 -0
- internetdata/_generated/models/database_redistribution_type_3_type_1.py +10 -0
- internetdata/_generated/models/database_standing.py +10 -0
- internetdata/_generated/models/database_version.py +97 -0
- internetdata/_generated/models/database_version_formats_item.py +9 -0
- internetdata/_generated/models/db_checksums.py +85 -0
- internetdata/_generated/models/download.py +161 -0
- internetdata/_generated/models/download_database_v2_format.py +9 -0
- internetdata/_generated/models/download_outcome.py +13 -0
- internetdata/_generated/models/error.py +62 -0
- internetdata/_generated/models/list_databases_response_200.py +75 -0
- internetdata/_generated/models/list_downloads_response_200.py +75 -0
- internetdata/_generated/types.py +54 -0
- internetdata/aio.py +268 -0
- internetdata/client.py +278 -0
- internetdata/errors.py +128 -0
- internetdata/models.py +197 -0
- internetdata/py.typed +0 -0
- internetdata-1.0.0.dist-info/METADATA +184 -0
- internetdata-1.0.0.dist-info/RECORD +46 -0
- internetdata-1.0.0.dist-info/WHEEL +4 -0
- internetdata-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from ... import errors
|
|
7
|
+
from ...client import AuthenticatedClient, Client
|
|
8
|
+
from ...models.error import Error
|
|
9
|
+
from ...models.list_downloads_response_200 import ListDownloadsResponse200
|
|
10
|
+
from ...types import UNSET, Response, Unset
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _get_kwargs(
|
|
14
|
+
*,
|
|
15
|
+
limit: int | Unset = 50,
|
|
16
|
+
) -> dict[str, Any]:
|
|
17
|
+
|
|
18
|
+
params: dict[str, Any] = {}
|
|
19
|
+
|
|
20
|
+
params["limit"] = limit
|
|
21
|
+
|
|
22
|
+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
|
|
23
|
+
|
|
24
|
+
_kwargs: dict[str, Any] = {
|
|
25
|
+
"method": "get",
|
|
26
|
+
"url": "/api/v2/database/downloads",
|
|
27
|
+
"params": params,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return _kwargs
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _parse_response(
|
|
34
|
+
*, client: AuthenticatedClient | Client, response: httpx.Response
|
|
35
|
+
) -> Error | ListDownloadsResponse200 | None:
|
|
36
|
+
if response.status_code == 200:
|
|
37
|
+
response_200 = ListDownloadsResponse200.from_dict(response.json())
|
|
38
|
+
|
|
39
|
+
return response_200
|
|
40
|
+
|
|
41
|
+
if response.status_code == 401:
|
|
42
|
+
response_401 = Error.from_dict(response.json())
|
|
43
|
+
|
|
44
|
+
return response_401
|
|
45
|
+
|
|
46
|
+
if client.raise_on_unexpected_status:
|
|
47
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
48
|
+
else:
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _build_response(
|
|
53
|
+
*, client: AuthenticatedClient | Client, response: httpx.Response
|
|
54
|
+
) -> Response[Error | ListDownloadsResponse200]:
|
|
55
|
+
return Response(
|
|
56
|
+
status_code=HTTPStatus(response.status_code),
|
|
57
|
+
content=response.content,
|
|
58
|
+
headers=response.headers,
|
|
59
|
+
parsed=_parse_response(client=client, response=response),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def sync_detailed(
|
|
64
|
+
*,
|
|
65
|
+
client: AuthenticatedClient,
|
|
66
|
+
limit: int | Unset = 50,
|
|
67
|
+
) -> Response[Error | ListDownloadsResponse200]:
|
|
68
|
+
"""Your organization's recent download attempts, newest first
|
|
69
|
+
|
|
70
|
+
Refusals are listed too: a denial is what answers "it stopped working",
|
|
71
|
+
and its absence answers nothing.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
limit (int | Unset): Default: 50.
|
|
75
|
+
|
|
76
|
+
Raises:
|
|
77
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
78
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
Response[Error | ListDownloadsResponse200]
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
kwargs = _get_kwargs(
|
|
85
|
+
limit=limit,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
response = client.get_httpx_client().request(
|
|
89
|
+
**kwargs,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
return _build_response(client=client, response=response)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def sync(
|
|
96
|
+
*,
|
|
97
|
+
client: AuthenticatedClient,
|
|
98
|
+
limit: int | Unset = 50,
|
|
99
|
+
) -> Error | ListDownloadsResponse200 | None:
|
|
100
|
+
"""Your organization's recent download attempts, newest first
|
|
101
|
+
|
|
102
|
+
Refusals are listed too: a denial is what answers "it stopped working",
|
|
103
|
+
and its absence answers nothing.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
limit (int | Unset): Default: 50.
|
|
107
|
+
|
|
108
|
+
Raises:
|
|
109
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
110
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
Error | ListDownloadsResponse200
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
return sync_detailed(
|
|
117
|
+
client=client,
|
|
118
|
+
limit=limit,
|
|
119
|
+
).parsed
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
async def asyncio_detailed(
|
|
123
|
+
*,
|
|
124
|
+
client: AuthenticatedClient,
|
|
125
|
+
limit: int | Unset = 50,
|
|
126
|
+
) -> Response[Error | ListDownloadsResponse200]:
|
|
127
|
+
"""Your organization's recent download attempts, newest first
|
|
128
|
+
|
|
129
|
+
Refusals are listed too: a denial is what answers "it stopped working",
|
|
130
|
+
and its absence answers nothing.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
limit (int | Unset): Default: 50.
|
|
134
|
+
|
|
135
|
+
Raises:
|
|
136
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
137
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
Response[Error | ListDownloadsResponse200]
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
kwargs = _get_kwargs(
|
|
144
|
+
limit=limit,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
|
148
|
+
|
|
149
|
+
return _build_response(client=client, response=response)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
async def asyncio(
|
|
153
|
+
*,
|
|
154
|
+
client: AuthenticatedClient,
|
|
155
|
+
limit: int | Unset = 50,
|
|
156
|
+
) -> Error | ListDownloadsResponse200 | None:
|
|
157
|
+
"""Your organization's recent download attempts, newest first
|
|
158
|
+
|
|
159
|
+
Refusals are listed too: a denial is what answers "it stopped working",
|
|
160
|
+
and its absence answers nothing.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
limit (int | Unset): Default: 50.
|
|
164
|
+
|
|
165
|
+
Raises:
|
|
166
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
167
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
Error | ListDownloadsResponse200
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
await asyncio_detailed(
|
|
175
|
+
client=client,
|
|
176
|
+
limit=limit,
|
|
177
|
+
)
|
|
178
|
+
).parsed
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import ssl
|
|
2
|
+
from typing import Any, Self
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
from attrs import define, evolve, field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@define
|
|
9
|
+
class Client:
|
|
10
|
+
"""A class for keeping track of data related to the API
|
|
11
|
+
|
|
12
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
13
|
+
|
|
14
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
15
|
+
|
|
16
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
17
|
+
|
|
18
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
19
|
+
|
|
20
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
21
|
+
httpx.TimeoutException if this is exceeded.
|
|
22
|
+
|
|
23
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
24
|
+
but can be set to False for testing purposes.
|
|
25
|
+
|
|
26
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
27
|
+
|
|
28
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Attributes:
|
|
32
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
33
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
34
|
+
argument to the constructor.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
38
|
+
_base_url: str = field(alias="base_url")
|
|
39
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
40
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
41
|
+
_timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
|
|
42
|
+
_verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
|
|
43
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
44
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
45
|
+
_client: httpx.Client | None = field(default=None, init=False)
|
|
46
|
+
_async_client: httpx.AsyncClient | None = field(default=None, init=False)
|
|
47
|
+
|
|
48
|
+
def with_headers(self, headers: dict[str, str]) -> "Client":
|
|
49
|
+
"""Get a new client matching this one with additional headers"""
|
|
50
|
+
if self._client is not None:
|
|
51
|
+
self._client.headers.update(headers)
|
|
52
|
+
if self._async_client is not None:
|
|
53
|
+
self._async_client.headers.update(headers)
|
|
54
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
55
|
+
|
|
56
|
+
def with_cookies(self, cookies: dict[str, str]) -> "Client":
|
|
57
|
+
"""Get a new client matching this one with additional cookies"""
|
|
58
|
+
if self._client is not None:
|
|
59
|
+
self._client.cookies.update(cookies)
|
|
60
|
+
if self._async_client is not None:
|
|
61
|
+
self._async_client.cookies.update(cookies)
|
|
62
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
63
|
+
|
|
64
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "Client":
|
|
65
|
+
"""Get a new client matching this one with a new timeout configuration"""
|
|
66
|
+
if self._client is not None:
|
|
67
|
+
self._client.timeout = timeout
|
|
68
|
+
if self._async_client is not None:
|
|
69
|
+
self._async_client.timeout = timeout
|
|
70
|
+
return evolve(self, timeout=timeout)
|
|
71
|
+
|
|
72
|
+
def set_httpx_client(self, client: httpx.Client) -> Self:
|
|
73
|
+
"""Manually set the underlying httpx.Client
|
|
74
|
+
|
|
75
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
76
|
+
"""
|
|
77
|
+
self._client = client
|
|
78
|
+
return self
|
|
79
|
+
|
|
80
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
81
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
82
|
+
if self._client is None:
|
|
83
|
+
self._client = httpx.Client(
|
|
84
|
+
base_url=self._base_url,
|
|
85
|
+
cookies=self._cookies,
|
|
86
|
+
headers=self._headers,
|
|
87
|
+
timeout=self._timeout,
|
|
88
|
+
verify=self._verify_ssl,
|
|
89
|
+
follow_redirects=self._follow_redirects,
|
|
90
|
+
**self._httpx_args,
|
|
91
|
+
)
|
|
92
|
+
return self._client
|
|
93
|
+
|
|
94
|
+
def __enter__(self) -> Self:
|
|
95
|
+
"""Enter a context manager for self.client - you cannot enter twice (see httpx docs)"""
|
|
96
|
+
self.get_httpx_client().__enter__()
|
|
97
|
+
return self
|
|
98
|
+
|
|
99
|
+
def __exit__(self, *args: object, **kwargs: Any) -> None:
|
|
100
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
101
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
102
|
+
|
|
103
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
|
|
104
|
+
"""Manually set the underlying httpx.AsyncClient
|
|
105
|
+
|
|
106
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
107
|
+
"""
|
|
108
|
+
self._async_client = async_client
|
|
109
|
+
return self
|
|
110
|
+
|
|
111
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
112
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
113
|
+
if self._async_client is None:
|
|
114
|
+
self._async_client = httpx.AsyncClient(
|
|
115
|
+
base_url=self._base_url,
|
|
116
|
+
cookies=self._cookies,
|
|
117
|
+
headers=self._headers,
|
|
118
|
+
timeout=self._timeout,
|
|
119
|
+
verify=self._verify_ssl,
|
|
120
|
+
follow_redirects=self._follow_redirects,
|
|
121
|
+
**self._httpx_args,
|
|
122
|
+
)
|
|
123
|
+
return self._async_client
|
|
124
|
+
|
|
125
|
+
async def __aenter__(self) -> Self:
|
|
126
|
+
"""Enter a context manager for underlying httpx.AsyncClient - you cannot enter twice (see httpx docs)"""
|
|
127
|
+
await self.get_async_httpx_client().__aenter__()
|
|
128
|
+
return self
|
|
129
|
+
|
|
130
|
+
async def __aexit__(self, *args: object, **kwargs: Any) -> None:
|
|
131
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
132
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@define
|
|
136
|
+
class AuthenticatedClient:
|
|
137
|
+
"""A Client which has been authenticated for use on secured endpoints
|
|
138
|
+
|
|
139
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
140
|
+
|
|
141
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
142
|
+
|
|
143
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
144
|
+
|
|
145
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
146
|
+
|
|
147
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
148
|
+
httpx.TimeoutException if this is exceeded.
|
|
149
|
+
|
|
150
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
151
|
+
but can be set to False for testing purposes.
|
|
152
|
+
|
|
153
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
154
|
+
|
|
155
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
Attributes:
|
|
159
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
160
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
161
|
+
argument to the constructor.
|
|
162
|
+
token: The token to use for authentication
|
|
163
|
+
prefix: The prefix to use for the Authorization header
|
|
164
|
+
auth_header_name: The name of the Authorization header
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
168
|
+
_base_url: str = field(alias="base_url")
|
|
169
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
170
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
171
|
+
_timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
|
|
172
|
+
_verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
|
|
173
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
174
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
175
|
+
_client: httpx.Client | None = field(default=None, init=False)
|
|
176
|
+
_async_client: httpx.AsyncClient | None = field(default=None, init=False)
|
|
177
|
+
|
|
178
|
+
token: str
|
|
179
|
+
prefix: str = "Bearer"
|
|
180
|
+
auth_header_name: str = "Authorization"
|
|
181
|
+
|
|
182
|
+
def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
|
|
183
|
+
"""Get a new client matching this one with additional headers"""
|
|
184
|
+
if self._client is not None:
|
|
185
|
+
self._client.headers.update(headers)
|
|
186
|
+
if self._async_client is not None:
|
|
187
|
+
self._async_client.headers.update(headers)
|
|
188
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
189
|
+
|
|
190
|
+
def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient":
|
|
191
|
+
"""Get a new client matching this one with additional cookies"""
|
|
192
|
+
if self._client is not None:
|
|
193
|
+
self._client.cookies.update(cookies)
|
|
194
|
+
if self._async_client is not None:
|
|
195
|
+
self._async_client.cookies.update(cookies)
|
|
196
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
197
|
+
|
|
198
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
|
|
199
|
+
"""Get a new client matching this one with a new timeout configuration"""
|
|
200
|
+
if self._client is not None:
|
|
201
|
+
self._client.timeout = timeout
|
|
202
|
+
if self._async_client is not None:
|
|
203
|
+
self._async_client.timeout = timeout
|
|
204
|
+
return evolve(self, timeout=timeout)
|
|
205
|
+
|
|
206
|
+
def set_httpx_client(self, client: httpx.Client) -> Self:
|
|
207
|
+
"""Manually set the underlying httpx.Client
|
|
208
|
+
|
|
209
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
210
|
+
"""
|
|
211
|
+
self._client = client
|
|
212
|
+
return self
|
|
213
|
+
|
|
214
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
215
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
216
|
+
if self._client is None:
|
|
217
|
+
self._headers[self.auth_header_name] = (
|
|
218
|
+
f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
219
|
+
)
|
|
220
|
+
self._client = httpx.Client(
|
|
221
|
+
base_url=self._base_url,
|
|
222
|
+
cookies=self._cookies,
|
|
223
|
+
headers=self._headers,
|
|
224
|
+
timeout=self._timeout,
|
|
225
|
+
verify=self._verify_ssl,
|
|
226
|
+
follow_redirects=self._follow_redirects,
|
|
227
|
+
**self._httpx_args,
|
|
228
|
+
)
|
|
229
|
+
return self._client
|
|
230
|
+
|
|
231
|
+
def __enter__(self) -> Self:
|
|
232
|
+
"""Enter a context manager for self.client - you cannot enter twice (see httpx docs)"""
|
|
233
|
+
self.get_httpx_client().__enter__()
|
|
234
|
+
return self
|
|
235
|
+
|
|
236
|
+
def __exit__(self, *args: object, **kwargs: Any) -> None:
|
|
237
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
238
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
239
|
+
|
|
240
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
|
|
241
|
+
"""Manually set the underlying httpx.AsyncClient
|
|
242
|
+
|
|
243
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
244
|
+
"""
|
|
245
|
+
self._async_client = async_client
|
|
246
|
+
return self
|
|
247
|
+
|
|
248
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
249
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
250
|
+
if self._async_client is None:
|
|
251
|
+
self._headers[self.auth_header_name] = (
|
|
252
|
+
f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
253
|
+
)
|
|
254
|
+
self._async_client = httpx.AsyncClient(
|
|
255
|
+
base_url=self._base_url,
|
|
256
|
+
cookies=self._cookies,
|
|
257
|
+
headers=self._headers,
|
|
258
|
+
timeout=self._timeout,
|
|
259
|
+
verify=self._verify_ssl,
|
|
260
|
+
follow_redirects=self._follow_redirects,
|
|
261
|
+
**self._httpx_args,
|
|
262
|
+
)
|
|
263
|
+
return self._async_client
|
|
264
|
+
|
|
265
|
+
async def __aenter__(self) -> Self:
|
|
266
|
+
"""Enter a context manager for underlying httpx.AsyncClient - you cannot enter twice (see httpx docs)"""
|
|
267
|
+
await self.get_async_httpx_client().__aenter__()
|
|
268
|
+
return self
|
|
269
|
+
|
|
270
|
+
async def __aexit__(self, *args: object, **kwargs: Any) -> None:
|
|
271
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
272
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Contains shared errors types that can be raised from API functions"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class UnexpectedStatus(Exception):
|
|
5
|
+
"""Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True"""
|
|
6
|
+
|
|
7
|
+
def __init__(self, status_code: int, content: bytes):
|
|
8
|
+
self.status_code = status_code
|
|
9
|
+
self.content = content
|
|
10
|
+
|
|
11
|
+
super().__init__(
|
|
12
|
+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
__all__ = ["UnexpectedStatus"]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Contains all the data models used in inputs/outputs"""
|
|
2
|
+
|
|
3
|
+
from .database import Database
|
|
4
|
+
from .database_checksum_v2_format import DatabaseChecksumV2Format
|
|
5
|
+
from .database_checksum_v2_response_200 import DatabaseChecksumV2Response200
|
|
6
|
+
from .database_checksum_v2_response_200_format import DatabaseChecksumV2Response200Format
|
|
7
|
+
from .database_metadata import DatabaseMetadata
|
|
8
|
+
from .database_metadata_column import DatabaseMetadataColumn
|
|
9
|
+
from .database_metadata_sample import DatabaseMetadataSample
|
|
10
|
+
from .database_metadata_sample_additional_property_item import (
|
|
11
|
+
DatabaseMetadataSampleAdditionalPropertyItem,
|
|
12
|
+
)
|
|
13
|
+
from .database_metadata_schema import DatabaseMetadataSchema
|
|
14
|
+
from .database_metadata_size import DatabaseMetadataSize
|
|
15
|
+
from .database_redistribution_type_1 import DatabaseRedistributionType1
|
|
16
|
+
from .database_redistribution_type_2_type_1 import DatabaseRedistributionType2Type1
|
|
17
|
+
from .database_redistribution_type_3_type_1 import DatabaseRedistributionType3Type1
|
|
18
|
+
from .database_standing import DatabaseStanding
|
|
19
|
+
from .database_version import DatabaseVersion
|
|
20
|
+
from .database_version_formats_item import DatabaseVersionFormatsItem
|
|
21
|
+
from .db_checksums import DbChecksums
|
|
22
|
+
from .download import Download
|
|
23
|
+
from .download_database_v2_format import DownloadDatabaseV2Format
|
|
24
|
+
from .download_outcome import DownloadOutcome
|
|
25
|
+
from .error import Error
|
|
26
|
+
from .list_databases_response_200 import ListDatabasesResponse200
|
|
27
|
+
from .list_downloads_response_200 import ListDownloadsResponse200
|
|
28
|
+
|
|
29
|
+
__all__ = (
|
|
30
|
+
"Database",
|
|
31
|
+
"DatabaseChecksumV2Format",
|
|
32
|
+
"DatabaseChecksumV2Response200",
|
|
33
|
+
"DatabaseChecksumV2Response200Format",
|
|
34
|
+
"DatabaseMetadata",
|
|
35
|
+
"DatabaseMetadataColumn",
|
|
36
|
+
"DatabaseMetadataSample",
|
|
37
|
+
"DatabaseMetadataSampleAdditionalPropertyItem",
|
|
38
|
+
"DatabaseMetadataSchema",
|
|
39
|
+
"DatabaseMetadataSize",
|
|
40
|
+
"DatabaseRedistributionType1",
|
|
41
|
+
"DatabaseRedistributionType2Type1",
|
|
42
|
+
"DatabaseRedistributionType3Type1",
|
|
43
|
+
"DatabaseStanding",
|
|
44
|
+
"DatabaseVersion",
|
|
45
|
+
"DatabaseVersionFormatsItem",
|
|
46
|
+
"DbChecksums",
|
|
47
|
+
"Download",
|
|
48
|
+
"DownloadDatabaseV2Format",
|
|
49
|
+
"DownloadOutcome",
|
|
50
|
+
"Error",
|
|
51
|
+
"ListDatabasesResponse200",
|
|
52
|
+
"ListDownloadsResponse200",
|
|
53
|
+
)
|