dungeoncoder 0.2.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.
- dungeoncoder/__init__.py +4 -0
- dungeoncoder/__main__.py +254 -0
- dungeoncoder/_api_config.py +6 -0
- dungeoncoder/_generated/__init__.py +8 -0
- dungeoncoder/_generated/api/__init__.py +1 -0
- dungeoncoder/_generated/api/game/__init__.py +1 -0
- dungeoncoder/_generated/api/game/get_statistics.py +158 -0
- dungeoncoder/_generated/api/game/get_version.py +166 -0
- dungeoncoder/_generated/api/hero/__init__.py +1 -0
- dungeoncoder/_generated/api/hero/ask_oracle.py +192 -0
- dungeoncoder/_generated/api/hero/configure.py +207 -0
- dungeoncoder/_generated/api/hero/drop.py +207 -0
- dungeoncoder/_generated/api/hero/get_inventory.py +188 -0
- dungeoncoder/_generated/api/hero/get_items_at_position.py +188 -0
- dungeoncoder/_generated/api/hero/interact.py +188 -0
- dungeoncoder/_generated/api/hero/is_abyss_in_front.py +188 -0
- dungeoncoder/_generated/api/hero/is_at_goal.py +192 -0
- dungeoncoder/_generated/api/hero/is_collision_in_front.py +188 -0
- dungeoncoder/_generated/api/hero/is_enemy_in_front.py +188 -0
- dungeoncoder/_generated/api/hero/is_facing_north.py +188 -0
- dungeoncoder/_generated/api/hero/is_switch_in_front.py +188 -0
- dungeoncoder/_generated/api/hero/is_torch_in_front.py +188 -0
- dungeoncoder/_generated/api/hero/move.py +188 -0
- dungeoncoder/_generated/api/hero/peek_item_value.py +211 -0
- dungeoncoder/_generated/api/hero/pickup.py +207 -0
- dungeoncoder/_generated/api/hero/read_item_value.py +188 -0
- dungeoncoder/_generated/api/hero/sense_goal.py +192 -0
- dungeoncoder/_generated/api/hero/set_pace.py +207 -0
- dungeoncoder/_generated/api/hero/turn_left.py +188 -0
- dungeoncoder/_generated/api/level/__init__.py +1 -0
- dungeoncoder/_generated/api/level/load_level.py +190 -0
- dungeoncoder/_generated/api/level/reset_level.py +158 -0
- dungeoncoder/_generated/client.py +271 -0
- dungeoncoder/_generated/errors.py +14 -0
- dungeoncoder/_generated/models/__init__.py +47 -0
- dungeoncoder/_generated/models/api_error_response.py +98 -0
- dungeoncoder/_generated/models/api_error_response_status.py +7 -0
- dungeoncoder/_generated/models/boolean_result.py +96 -0
- dungeoncoder/_generated/models/boolean_result_status.py +7 -0
- dungeoncoder/_generated/models/configure_params.py +84 -0
- dungeoncoder/_generated/models/distance_param.py +76 -0
- dungeoncoder/_generated/models/name_param.py +76 -0
- dungeoncoder/_generated/models/nullable_integer_result.py +104 -0
- dungeoncoder/_generated/models/nullable_integer_result_status.py +7 -0
- dungeoncoder/_generated/models/nullable_string_result.py +104 -0
- dungeoncoder/_generated/models/nullable_string_result_status.py +7 -0
- dungeoncoder/_generated/models/pace_params.py +76 -0
- dungeoncoder/_generated/models/statistics.py +217 -0
- dungeoncoder/_generated/models/statistics_result.py +104 -0
- dungeoncoder/_generated/models/statistics_result_status.py +7 -0
- dungeoncoder/_generated/models/string_array_result.py +100 -0
- dungeoncoder/_generated/models/string_array_result_status.py +7 -0
- dungeoncoder/_generated/models/tiled_level.py +67 -0
- dungeoncoder/_generated/models/version_result.py +104 -0
- dungeoncoder/_generated/models/version_result_result.py +84 -0
- dungeoncoder/_generated/models/version_result_status.py +7 -0
- dungeoncoder/_generated/types.py +53 -0
- dungeoncoder/asciimap.py +824 -0
- dungeoncoder/dungeoncoder.py +482 -0
- dungeoncoder/generator.py +213 -0
- dungeoncoder/packs/gelaende.json +1 -0
- dungeoncoder/packs/items.json +67 -0
- dungeoncoder/packs/station.json +1 -0
- dungeoncoder/packs/studio.json +1 -0
- dungeoncoder/packs/tilesets.json +1 -0
- dungeoncoder/packs/werkstatt.json +1 -0
- dungeoncoder/replay.py +80 -0
- dungeoncoder/requirements.txt +2 -0
- dungeoncoder/sim.py +792 -0
- dungeoncoder/testing.py +63 -0
- dungeoncoder/trace.py +92 -0
- dungeoncoder/variants.py +112 -0
- dungeoncoder-0.2.0.dist-info/METADATA +37 -0
- dungeoncoder-0.2.0.dist-info/RECORD +77 -0
- dungeoncoder-0.2.0.dist-info/WHEEL +5 -0
- dungeoncoder-0.2.0.dist-info/licenses/LICENSE.txt +25 -0
- dungeoncoder-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any, cast
|
|
3
|
+
from urllib.parse import quote
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ...client import AuthenticatedClient, Client
|
|
8
|
+
from ...types import Response, UNSET
|
|
9
|
+
from ... import errors
|
|
10
|
+
|
|
11
|
+
from ...models.api_error_response import ApiErrorResponse
|
|
12
|
+
from ...models.boolean_result import BooleanResult
|
|
13
|
+
from typing import cast
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _get_kwargs(
|
|
18
|
+
|
|
19
|
+
) -> dict[str, Any]:
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
_kwargs: dict[str, Any] = {
|
|
27
|
+
"method": "post",
|
|
28
|
+
"url": "/level/reset",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
return _kwargs
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> ApiErrorResponse | BooleanResult | None:
|
|
37
|
+
if response.status_code == 200:
|
|
38
|
+
response_200 = BooleanResult.from_dict(response.json())
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
return response_200
|
|
43
|
+
|
|
44
|
+
if response.status_code == 500:
|
|
45
|
+
response_500 = ApiErrorResponse.from_dict(response.json())
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
return response_500
|
|
50
|
+
|
|
51
|
+
if client.raise_on_unexpected_status:
|
|
52
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
53
|
+
else:
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[ApiErrorResponse | BooleanResult]:
|
|
58
|
+
return Response(
|
|
59
|
+
status_code=HTTPStatus(response.status_code),
|
|
60
|
+
content=response.content,
|
|
61
|
+
headers=response.headers,
|
|
62
|
+
parsed=_parse_response(client=client, response=response),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def sync_detailed(
|
|
67
|
+
*,
|
|
68
|
+
client: AuthenticatedClient | Client,
|
|
69
|
+
|
|
70
|
+
) -> Response[ApiErrorResponse | BooleanResult]:
|
|
71
|
+
""" Reload the most recently loaded level from scratch.
|
|
72
|
+
|
|
73
|
+
Raises:
|
|
74
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
75
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Response[ApiErrorResponse | BooleanResult]
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
kwargs = _get_kwargs(
|
|
83
|
+
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
response = client.get_httpx_client().request(
|
|
87
|
+
**kwargs,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
return _build_response(client=client, response=response)
|
|
91
|
+
|
|
92
|
+
def sync(
|
|
93
|
+
*,
|
|
94
|
+
client: AuthenticatedClient | Client,
|
|
95
|
+
|
|
96
|
+
) -> ApiErrorResponse | BooleanResult | None:
|
|
97
|
+
""" Reload the most recently loaded level from scratch.
|
|
98
|
+
|
|
99
|
+
Raises:
|
|
100
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
101
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
ApiErrorResponse | BooleanResult
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
return sync_detailed(
|
|
109
|
+
client=client,
|
|
110
|
+
|
|
111
|
+
).parsed
|
|
112
|
+
|
|
113
|
+
async def asyncio_detailed(
|
|
114
|
+
*,
|
|
115
|
+
client: AuthenticatedClient | Client,
|
|
116
|
+
|
|
117
|
+
) -> Response[ApiErrorResponse | BooleanResult]:
|
|
118
|
+
""" Reload the most recently loaded level from scratch.
|
|
119
|
+
|
|
120
|
+
Raises:
|
|
121
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
122
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
Response[ApiErrorResponse | BooleanResult]
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
kwargs = _get_kwargs(
|
|
130
|
+
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
response = await client.get_async_httpx_client().request(
|
|
134
|
+
**kwargs
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
return _build_response(client=client, response=response)
|
|
138
|
+
|
|
139
|
+
async def asyncio(
|
|
140
|
+
*,
|
|
141
|
+
client: AuthenticatedClient | Client,
|
|
142
|
+
|
|
143
|
+
) -> ApiErrorResponse | BooleanResult | None:
|
|
144
|
+
""" Reload the most recently loaded level from scratch.
|
|
145
|
+
|
|
146
|
+
Raises:
|
|
147
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
148
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
ApiErrorResponse | BooleanResult
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
return (await asyncio_detailed(
|
|
156
|
+
client=client,
|
|
157
|
+
|
|
158
|
+
)).parsed
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import ssl
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from attrs import define, field, evolve
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@define
|
|
12
|
+
class Client:
|
|
13
|
+
"""A class for keeping track of data related to the API
|
|
14
|
+
|
|
15
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
16
|
+
|
|
17
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
18
|
+
|
|
19
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
20
|
+
|
|
21
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
22
|
+
|
|
23
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
24
|
+
httpx.TimeoutException if this is exceeded.
|
|
25
|
+
|
|
26
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
27
|
+
but can be set to False for testing purposes.
|
|
28
|
+
|
|
29
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
30
|
+
|
|
31
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Attributes:
|
|
35
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
36
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
37
|
+
argument to the constructor.
|
|
38
|
+
"""
|
|
39
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
40
|
+
_base_url: str = field(alias="base_url")
|
|
41
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
42
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
43
|
+
_timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
|
|
44
|
+
_verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
|
|
45
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
46
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
47
|
+
_client: httpx.Client | None = field(default=None, init=False)
|
|
48
|
+
_async_client: httpx.AsyncClient | None = field(default=None, init=False)
|
|
49
|
+
|
|
50
|
+
def with_headers(self, headers: dict[str, str]) -> "Client":
|
|
51
|
+
"""Get a new client matching this one with additional headers"""
|
|
52
|
+
if self._client is not None:
|
|
53
|
+
self._client.headers.update(headers)
|
|
54
|
+
if self._async_client is not None:
|
|
55
|
+
self._async_client.headers.update(headers)
|
|
56
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
57
|
+
|
|
58
|
+
def with_cookies(self, cookies: dict[str, str]) -> "Client":
|
|
59
|
+
"""Get a new client matching this one with additional cookies"""
|
|
60
|
+
if self._client is not None:
|
|
61
|
+
self._client.cookies.update(cookies)
|
|
62
|
+
if self._async_client is not None:
|
|
63
|
+
self._async_client.cookies.update(cookies)
|
|
64
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
65
|
+
|
|
66
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "Client":
|
|
67
|
+
"""Get a new client matching this one with a new timeout configuration"""
|
|
68
|
+
if self._client is not None:
|
|
69
|
+
self._client.timeout = timeout
|
|
70
|
+
if self._async_client is not None:
|
|
71
|
+
self._async_client.timeout = timeout
|
|
72
|
+
return evolve(self, timeout=timeout)
|
|
73
|
+
|
|
74
|
+
def set_httpx_client(self, client: httpx.Client) -> "Client":
|
|
75
|
+
"""Manually set the underlying httpx.Client
|
|
76
|
+
|
|
77
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
78
|
+
"""
|
|
79
|
+
self._client = client
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
83
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
84
|
+
if self._client is None:
|
|
85
|
+
self._client = httpx.Client(
|
|
86
|
+
base_url=self._base_url,
|
|
87
|
+
cookies=self._cookies,
|
|
88
|
+
headers=self._headers,
|
|
89
|
+
timeout=self._timeout,
|
|
90
|
+
verify=self._verify_ssl,
|
|
91
|
+
follow_redirects=self._follow_redirects,
|
|
92
|
+
**self._httpx_args,
|
|
93
|
+
)
|
|
94
|
+
return self._client
|
|
95
|
+
|
|
96
|
+
def __enter__(self) -> "Client":
|
|
97
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
|
98
|
+
self.get_httpx_client().__enter__()
|
|
99
|
+
return self
|
|
100
|
+
|
|
101
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
|
102
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
103
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
104
|
+
|
|
105
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
|
|
106
|
+
"""Manually set the underlying httpx.AsyncClient
|
|
107
|
+
|
|
108
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
109
|
+
"""
|
|
110
|
+
self._async_client = async_client
|
|
111
|
+
return self
|
|
112
|
+
|
|
113
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
114
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
115
|
+
if self._async_client is None:
|
|
116
|
+
self._async_client = httpx.AsyncClient(
|
|
117
|
+
base_url=self._base_url,
|
|
118
|
+
cookies=self._cookies,
|
|
119
|
+
headers=self._headers,
|
|
120
|
+
timeout=self._timeout,
|
|
121
|
+
verify=self._verify_ssl,
|
|
122
|
+
follow_redirects=self._follow_redirects,
|
|
123
|
+
**self._httpx_args,
|
|
124
|
+
)
|
|
125
|
+
return self._async_client
|
|
126
|
+
|
|
127
|
+
async def __aenter__(self) -> "Client":
|
|
128
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
|
129
|
+
await self.get_async_httpx_client().__aenter__()
|
|
130
|
+
return self
|
|
131
|
+
|
|
132
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
|
133
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
134
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@define
|
|
138
|
+
class AuthenticatedClient:
|
|
139
|
+
"""A Client which has been authenticated for use on secured endpoints
|
|
140
|
+
|
|
141
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
142
|
+
|
|
143
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
144
|
+
|
|
145
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
146
|
+
|
|
147
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
148
|
+
|
|
149
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
150
|
+
httpx.TimeoutException if this is exceeded.
|
|
151
|
+
|
|
152
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
153
|
+
but can be set to False for testing purposes.
|
|
154
|
+
|
|
155
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
156
|
+
|
|
157
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
Attributes:
|
|
161
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
162
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
163
|
+
argument to the constructor.
|
|
164
|
+
token: The token to use for authentication
|
|
165
|
+
prefix: The prefix to use for the Authorization header
|
|
166
|
+
auth_header_name: The name of the Authorization header
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
170
|
+
_base_url: str = field(alias="base_url")
|
|
171
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
172
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
173
|
+
_timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
|
|
174
|
+
_verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
|
|
175
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
176
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
177
|
+
_client: httpx.Client | None = field(default=None, init=False)
|
|
178
|
+
_async_client: httpx.AsyncClient | None = field(default=None, init=False)
|
|
179
|
+
|
|
180
|
+
token: str
|
|
181
|
+
prefix: str = "Bearer"
|
|
182
|
+
auth_header_name: str = "Authorization"
|
|
183
|
+
|
|
184
|
+
def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
|
|
185
|
+
"""Get a new client matching this one with additional headers"""
|
|
186
|
+
if self._client is not None:
|
|
187
|
+
self._client.headers.update(headers)
|
|
188
|
+
if self._async_client is not None:
|
|
189
|
+
self._async_client.headers.update(headers)
|
|
190
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
191
|
+
|
|
192
|
+
def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient":
|
|
193
|
+
"""Get a new client matching this one with additional cookies"""
|
|
194
|
+
if self._client is not None:
|
|
195
|
+
self._client.cookies.update(cookies)
|
|
196
|
+
if self._async_client is not None:
|
|
197
|
+
self._async_client.cookies.update(cookies)
|
|
198
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
199
|
+
|
|
200
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
|
|
201
|
+
"""Get a new client matching this one with a new timeout configuration"""
|
|
202
|
+
if self._client is not None:
|
|
203
|
+
self._client.timeout = timeout
|
|
204
|
+
if self._async_client is not None:
|
|
205
|
+
self._async_client.timeout = timeout
|
|
206
|
+
return evolve(self, timeout=timeout)
|
|
207
|
+
|
|
208
|
+
def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
|
|
209
|
+
"""Manually set the underlying httpx.Client
|
|
210
|
+
|
|
211
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
212
|
+
"""
|
|
213
|
+
self._client = client
|
|
214
|
+
return self
|
|
215
|
+
|
|
216
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
217
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
218
|
+
if self._client is None:
|
|
219
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
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) -> "AuthenticatedClient":
|
|
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: Any, **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) -> "AuthenticatedClient":
|
|
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] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
252
|
+
self._async_client = httpx.AsyncClient(
|
|
253
|
+
base_url=self._base_url,
|
|
254
|
+
cookies=self._cookies,
|
|
255
|
+
headers=self._headers,
|
|
256
|
+
timeout=self._timeout,
|
|
257
|
+
verify=self._verify_ssl,
|
|
258
|
+
follow_redirects=self._follow_redirects,
|
|
259
|
+
**self._httpx_args,
|
|
260
|
+
)
|
|
261
|
+
return self._async_client
|
|
262
|
+
|
|
263
|
+
async def __aenter__(self) -> "AuthenticatedClient":
|
|
264
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
|
265
|
+
await self.get_async_httpx_client().__aenter__()
|
|
266
|
+
return self
|
|
267
|
+
|
|
268
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
|
269
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
270
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
|
271
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
""" Contains shared errors types that can be raised from API functions """
|
|
2
|
+
|
|
3
|
+
class UnexpectedStatus(Exception):
|
|
4
|
+
"""Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True"""
|
|
5
|
+
|
|
6
|
+
def __init__(self, status_code: int, content: bytes):
|
|
7
|
+
self.status_code = status_code
|
|
8
|
+
self.content = content
|
|
9
|
+
|
|
10
|
+
super().__init__(
|
|
11
|
+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = ["UnexpectedStatus"]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
""" Contains all the data models used in inputs/outputs """
|
|
2
|
+
|
|
3
|
+
from .api_error_response import ApiErrorResponse
|
|
4
|
+
from .api_error_response_status import ApiErrorResponseStatus
|
|
5
|
+
from .boolean_result import BooleanResult
|
|
6
|
+
from .boolean_result_status import BooleanResultStatus
|
|
7
|
+
from .configure_params import ConfigureParams
|
|
8
|
+
from .distance_param import DistanceParam
|
|
9
|
+
from .name_param import NameParam
|
|
10
|
+
from .nullable_integer_result import NullableIntegerResult
|
|
11
|
+
from .nullable_integer_result_status import NullableIntegerResultStatus
|
|
12
|
+
from .nullable_string_result import NullableStringResult
|
|
13
|
+
from .nullable_string_result_status import NullableStringResultStatus
|
|
14
|
+
from .pace_params import PaceParams
|
|
15
|
+
from .statistics import Statistics
|
|
16
|
+
from .statistics_result import StatisticsResult
|
|
17
|
+
from .statistics_result_status import StatisticsResultStatus
|
|
18
|
+
from .string_array_result import StringArrayResult
|
|
19
|
+
from .string_array_result_status import StringArrayResultStatus
|
|
20
|
+
from .tiled_level import TiledLevel
|
|
21
|
+
from .version_result import VersionResult
|
|
22
|
+
from .version_result_result import VersionResultResult
|
|
23
|
+
from .version_result_status import VersionResultStatus
|
|
24
|
+
|
|
25
|
+
__all__ = (
|
|
26
|
+
"ApiErrorResponse",
|
|
27
|
+
"ApiErrorResponseStatus",
|
|
28
|
+
"BooleanResult",
|
|
29
|
+
"BooleanResultStatus",
|
|
30
|
+
"ConfigureParams",
|
|
31
|
+
"DistanceParam",
|
|
32
|
+
"NameParam",
|
|
33
|
+
"NullableIntegerResult",
|
|
34
|
+
"NullableIntegerResultStatus",
|
|
35
|
+
"NullableStringResult",
|
|
36
|
+
"NullableStringResultStatus",
|
|
37
|
+
"PaceParams",
|
|
38
|
+
"Statistics",
|
|
39
|
+
"StatisticsResult",
|
|
40
|
+
"StatisticsResultStatus",
|
|
41
|
+
"StringArrayResult",
|
|
42
|
+
"StringArrayResultStatus",
|
|
43
|
+
"TiledLevel",
|
|
44
|
+
"VersionResult",
|
|
45
|
+
"VersionResultResult",
|
|
46
|
+
"VersionResultStatus",
|
|
47
|
+
)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import Any, TypeVar, BinaryIO, TextIO, TYPE_CHECKING, Generator
|
|
5
|
+
|
|
6
|
+
from attrs import define as _attrs_define
|
|
7
|
+
from attrs import field as _attrs_field
|
|
8
|
+
|
|
9
|
+
from ..types import UNSET, Unset
|
|
10
|
+
|
|
11
|
+
from ..models.api_error_response_status import ApiErrorResponseStatus
|
|
12
|
+
from ..types import UNSET, Unset
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
T = TypeVar("T", bound="ApiErrorResponse")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@_attrs_define
|
|
24
|
+
class ApiErrorResponse:
|
|
25
|
+
"""
|
|
26
|
+
Attributes:
|
|
27
|
+
status (ApiErrorResponseStatus):
|
|
28
|
+
message (str):
|
|
29
|
+
exception (str | Unset):
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
status: ApiErrorResponseStatus
|
|
33
|
+
message: str
|
|
34
|
+
exception: str | Unset = UNSET
|
|
35
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def to_dict(self) -> dict[str, Any]:
|
|
42
|
+
status = self.status.value
|
|
43
|
+
|
|
44
|
+
message = self.message
|
|
45
|
+
|
|
46
|
+
exception = self.exception
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
field_dict: dict[str, Any] = {}
|
|
50
|
+
field_dict.update(self.additional_properties)
|
|
51
|
+
field_dict.update({
|
|
52
|
+
"status": status,
|
|
53
|
+
"message": message,
|
|
54
|
+
})
|
|
55
|
+
if exception is not UNSET:
|
|
56
|
+
field_dict["exception"] = exception
|
|
57
|
+
|
|
58
|
+
return field_dict
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@classmethod
|
|
63
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
64
|
+
d = dict(src_dict)
|
|
65
|
+
status = ApiErrorResponseStatus(d.pop("status"))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
message = d.pop("message")
|
|
71
|
+
|
|
72
|
+
exception = d.pop("exception", UNSET)
|
|
73
|
+
|
|
74
|
+
api_error_response = cls(
|
|
75
|
+
status=status,
|
|
76
|
+
message=message,
|
|
77
|
+
exception=exception,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
api_error_response.additional_properties = d
|
|
82
|
+
return api_error_response
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def additional_keys(self) -> list[str]:
|
|
86
|
+
return list(self.additional_properties.keys())
|
|
87
|
+
|
|
88
|
+
def __getitem__(self, key: str) -> Any:
|
|
89
|
+
return self.additional_properties[key]
|
|
90
|
+
|
|
91
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
92
|
+
self.additional_properties[key] = value
|
|
93
|
+
|
|
94
|
+
def __delitem__(self, key: str) -> None:
|
|
95
|
+
del self.additional_properties[key]
|
|
96
|
+
|
|
97
|
+
def __contains__(self, key: str) -> bool:
|
|
98
|
+
return key in self.additional_properties
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import Any, TypeVar, BinaryIO, TextIO, TYPE_CHECKING, Generator
|
|
5
|
+
|
|
6
|
+
from attrs import define as _attrs_define
|
|
7
|
+
from attrs import field as _attrs_field
|
|
8
|
+
|
|
9
|
+
from ..types import UNSET, Unset
|
|
10
|
+
|
|
11
|
+
from ..models.boolean_result_status import BooleanResultStatus
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
T = TypeVar("T", bound="BooleanResult")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@_attrs_define
|
|
23
|
+
class BooleanResult:
|
|
24
|
+
"""
|
|
25
|
+
Attributes:
|
|
26
|
+
status (BooleanResultStatus):
|
|
27
|
+
message (str):
|
|
28
|
+
result (bool):
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
status: BooleanResultStatus
|
|
32
|
+
message: str
|
|
33
|
+
result: bool
|
|
34
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def to_dict(self) -> dict[str, Any]:
|
|
41
|
+
status = self.status.value
|
|
42
|
+
|
|
43
|
+
message = self.message
|
|
44
|
+
|
|
45
|
+
result = self.result
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
field_dict: dict[str, Any] = {}
|
|
49
|
+
field_dict.update(self.additional_properties)
|
|
50
|
+
field_dict.update({
|
|
51
|
+
"status": status,
|
|
52
|
+
"message": message,
|
|
53
|
+
"result": result,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return field_dict
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
62
|
+
d = dict(src_dict)
|
|
63
|
+
status = BooleanResultStatus(d.pop("status"))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
message = d.pop("message")
|
|
69
|
+
|
|
70
|
+
result = d.pop("result")
|
|
71
|
+
|
|
72
|
+
boolean_result = cls(
|
|
73
|
+
status=status,
|
|
74
|
+
message=message,
|
|
75
|
+
result=result,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
boolean_result.additional_properties = d
|
|
80
|
+
return boolean_result
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def additional_keys(self) -> list[str]:
|
|
84
|
+
return list(self.additional_properties.keys())
|
|
85
|
+
|
|
86
|
+
def __getitem__(self, key: str) -> Any:
|
|
87
|
+
return self.additional_properties[key]
|
|
88
|
+
|
|
89
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
90
|
+
self.additional_properties[key] = value
|
|
91
|
+
|
|
92
|
+
def __delitem__(self, key: str) -> None:
|
|
93
|
+
del self.additional_properties[key]
|
|
94
|
+
|
|
95
|
+
def __contains__(self, key: str) -> bool:
|
|
96
|
+
return key in self.additional_properties
|