|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any, Optional, Union, cast |
| 3 | + |
| 4 | +import httpx |
| 5 | + |
| 6 | +from ...client import AuthenticatedClient, Client |
| 7 | +from ...types import Response, UNSET |
| 8 | +from ... import errors |
| 9 | + |
| 10 | +from ...models.hpc_run import HpcRun |
| 11 | +from ...models.http_validation_error import HTTPValidationError |
| 12 | +from typing import cast |
| 13 | + |
| 14 | + |
| 15 | +def _get_kwargs( |
| 16 | + *, |
| 17 | + body: list[int], |
| 18 | +) -> dict[str, Any]: |
| 19 | + headers: dict[str, Any] = {} |
| 20 | + |
| 21 | + _kwargs: dict[str, Any] = { |
| 22 | + "method": "get", |
| 23 | + "url": "/results/simulations/status/batch", |
| 24 | + } |
| 25 | + |
| 26 | + _kwargs["json"] = body |
| 27 | + |
| 28 | + headers["Content-Type"] = "application/json" |
| 29 | + |
| 30 | + _kwargs["headers"] = headers |
| 31 | + return _kwargs |
| 32 | + |
| 33 | + |
| 34 | +def _parse_response( |
| 35 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 36 | +) -> Optional[Union[HTTPValidationError, list["HpcRun"]]]: |
| 37 | + if response.status_code == 200: |
| 38 | + response_200 = [] |
| 39 | + _response_200 = response.json() |
| 40 | + for response_200_item_data in _response_200: |
| 41 | + response_200_item = HpcRun.from_dict(response_200_item_data) |
| 42 | + |
| 43 | + response_200.append(response_200_item) |
| 44 | + |
| 45 | + return response_200 |
| 46 | + if response.status_code == 422: |
| 47 | + response_422 = HTTPValidationError.from_dict(response.json()) |
| 48 | + |
| 49 | + return response_422 |
| 50 | + if client.raise_on_unexpected_status: |
| 51 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 52 | + else: |
| 53 | + return None |
| 54 | + |
| 55 | + |
| 56 | +def _build_response( |
| 57 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 58 | +) -> Response[Union[HTTPValidationError, list["HpcRun"]]]: |
| 59 | + return Response( |
| 60 | + status_code=HTTPStatus(response.status_code), |
| 61 | + content=response.content, |
| 62 | + headers=response.headers, |
| 63 | + parsed=_parse_response(client=client, response=response), |
| 64 | + ) |
| 65 | + |
| 66 | + |
| 67 | +def sync_detailed( |
| 68 | + *, |
| 69 | + client: Union[AuthenticatedClient, Client], |
| 70 | + body: list[int], |
| 71 | +) -> Response[Union[HTTPValidationError, list["HpcRun"]]]: |
| 72 | + """Get simulation status records for a list of IDs |
| 73 | +
|
| 74 | + Args: |
| 75 | + body (list[int]): |
| 76 | +
|
| 77 | + Raises: |
| 78 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 79 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 80 | +
|
| 81 | + Returns: |
| 82 | + Response[Union[HTTPValidationError, list['HpcRun']]] |
| 83 | + """ |
| 84 | + |
| 85 | + kwargs = _get_kwargs( |
| 86 | + body=body, |
| 87 | + ) |
| 88 | + |
| 89 | + response = client.get_httpx_client().request( |
| 90 | + **kwargs, |
| 91 | + ) |
| 92 | + |
| 93 | + return _build_response(client=client, response=response) |
| 94 | + |
| 95 | + |
| 96 | +def sync( |
| 97 | + *, |
| 98 | + client: Union[AuthenticatedClient, Client], |
| 99 | + body: list[int], |
| 100 | +) -> Optional[Union[HTTPValidationError, list["HpcRun"]]]: |
| 101 | + """Get simulation status records for a list of IDs |
| 102 | +
|
| 103 | + Args: |
| 104 | + body (list[int]): |
| 105 | +
|
| 106 | + Raises: |
| 107 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 108 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 109 | +
|
| 110 | + Returns: |
| 111 | + Union[HTTPValidationError, list['HpcRun']] |
| 112 | + """ |
| 113 | + |
| 114 | + return sync_detailed( |
| 115 | + client=client, |
| 116 | + body=body, |
| 117 | + ).parsed |
| 118 | + |
| 119 | + |
| 120 | +async def asyncio_detailed( |
| 121 | + *, |
| 122 | + client: Union[AuthenticatedClient, Client], |
| 123 | + body: list[int], |
| 124 | +) -> Response[Union[HTTPValidationError, list["HpcRun"]]]: |
| 125 | + """Get simulation status records for a list of IDs |
| 126 | +
|
| 127 | + Args: |
| 128 | + body (list[int]): |
| 129 | +
|
| 130 | + Raises: |
| 131 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 132 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 133 | +
|
| 134 | + Returns: |
| 135 | + Response[Union[HTTPValidationError, list['HpcRun']]] |
| 136 | + """ |
| 137 | + |
| 138 | + kwargs = _get_kwargs( |
| 139 | + body=body, |
| 140 | + ) |
| 141 | + |
| 142 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 143 | + |
| 144 | + return _build_response(client=client, response=response) |
| 145 | + |
| 146 | + |
| 147 | +async def asyncio( |
| 148 | + *, |
| 149 | + client: Union[AuthenticatedClient, Client], |
| 150 | + body: list[int], |
| 151 | +) -> Optional[Union[HTTPValidationError, list["HpcRun"]]]: |
| 152 | + """Get simulation status records for a list of IDs |
| 153 | +
|
| 154 | + Args: |
| 155 | + body (list[int]): |
| 156 | +
|
| 157 | + Raises: |
| 158 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 159 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 160 | +
|
| 161 | + Returns: |
| 162 | + Union[HTTPValidationError, list['HpcRun']] |
| 163 | + """ |
| 164 | + |
| 165 | + return ( |
| 166 | + await asyncio_detailed( |
| 167 | + client=client, |
| 168 | + body=body, |
| 169 | + ) |
| 170 | + ).parsed |
0 commit comments