|
| 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.body_execute_sedml import BodyExecuteSedml |
| 11 | +from ...models.http_validation_error import HTTPValidationError |
| 12 | +from ...models.simulation_experiment import SimulationExperiment |
| 13 | +from ...models.tool_suites import ToolSuites |
| 14 | +from typing import cast |
| 15 | + |
| 16 | + |
| 17 | +def _get_kwargs( |
| 18 | + *, |
| 19 | + body: BodyExecuteSedml, |
| 20 | + tool_suite: ToolSuites, |
| 21 | +) -> dict[str, Any]: |
| 22 | + headers: dict[str, Any] = {} |
| 23 | + |
| 24 | + params: dict[str, Any] = {} |
| 25 | + |
| 26 | + json_tool_suite = tool_suite.value |
| 27 | + params["tool_suite"] = json_tool_suite |
| 28 | + |
| 29 | + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} |
| 30 | + |
| 31 | + _kwargs: dict[str, Any] = { |
| 32 | + "method": "post", |
| 33 | + "url": "/core/simulation/execute/sedml", |
| 34 | + "params": params, |
| 35 | + } |
| 36 | + |
| 37 | + _kwargs["files"] = body.to_multipart() |
| 38 | + |
| 39 | + _kwargs["headers"] = headers |
| 40 | + return _kwargs |
| 41 | + |
| 42 | + |
| 43 | +def _parse_response( |
| 44 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 45 | +) -> Optional[Union[HTTPValidationError, SimulationExperiment]]: |
| 46 | + if response.status_code == 200: |
| 47 | + response_200 = SimulationExperiment.from_dict(response.json()) |
| 48 | + |
| 49 | + return response_200 |
| 50 | + if response.status_code == 422: |
| 51 | + response_422 = HTTPValidationError.from_dict(response.json()) |
| 52 | + |
| 53 | + return response_422 |
| 54 | + if client.raise_on_unexpected_status: |
| 55 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 56 | + else: |
| 57 | + return None |
| 58 | + |
| 59 | + |
| 60 | +def _build_response( |
| 61 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 62 | +) -> Response[Union[HTTPValidationError, SimulationExperiment]]: |
| 63 | + return Response( |
| 64 | + status_code=HTTPStatus(response.status_code), |
| 65 | + content=response.content, |
| 66 | + headers=response.headers, |
| 67 | + parsed=_parse_response(client=client, response=response), |
| 68 | + ) |
| 69 | + |
| 70 | + |
| 71 | +def sync_detailed( |
| 72 | + *, |
| 73 | + client: Union[AuthenticatedClient, Client], |
| 74 | + body: BodyExecuteSedml, |
| 75 | + tool_suite: ToolSuites, |
| 76 | +) -> Response[Union[HTTPValidationError, SimulationExperiment]]: |
| 77 | + """Execute sedml |
| 78 | +
|
| 79 | + Args: |
| 80 | + tool_suite (ToolSuites): |
| 81 | + body (BodyExecuteSedml): |
| 82 | +
|
| 83 | + Raises: |
| 84 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 85 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 86 | +
|
| 87 | + Returns: |
| 88 | + Response[Union[HTTPValidationError, SimulationExperiment]] |
| 89 | + """ |
| 90 | + |
| 91 | + kwargs = _get_kwargs( |
| 92 | + body=body, |
| 93 | + tool_suite=tool_suite, |
| 94 | + ) |
| 95 | + |
| 96 | + response = client.get_httpx_client().request( |
| 97 | + **kwargs, |
| 98 | + ) |
| 99 | + |
| 100 | + return _build_response(client=client, response=response) |
| 101 | + |
| 102 | + |
| 103 | +def sync( |
| 104 | + *, |
| 105 | + client: Union[AuthenticatedClient, Client], |
| 106 | + body: BodyExecuteSedml, |
| 107 | + tool_suite: ToolSuites, |
| 108 | +) -> Optional[Union[HTTPValidationError, SimulationExperiment]]: |
| 109 | + """Execute sedml |
| 110 | +
|
| 111 | + Args: |
| 112 | + tool_suite (ToolSuites): |
| 113 | + body (BodyExecuteSedml): |
| 114 | +
|
| 115 | + Raises: |
| 116 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 117 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 118 | +
|
| 119 | + Returns: |
| 120 | + Union[HTTPValidationError, SimulationExperiment] |
| 121 | + """ |
| 122 | + |
| 123 | + return sync_detailed( |
| 124 | + client=client, |
| 125 | + body=body, |
| 126 | + tool_suite=tool_suite, |
| 127 | + ).parsed |
| 128 | + |
| 129 | + |
| 130 | +async def asyncio_detailed( |
| 131 | + *, |
| 132 | + client: Union[AuthenticatedClient, Client], |
| 133 | + body: BodyExecuteSedml, |
| 134 | + tool_suite: ToolSuites, |
| 135 | +) -> Response[Union[HTTPValidationError, SimulationExperiment]]: |
| 136 | + """Execute sedml |
| 137 | +
|
| 138 | + Args: |
| 139 | + tool_suite (ToolSuites): |
| 140 | + body (BodyExecuteSedml): |
| 141 | +
|
| 142 | + Raises: |
| 143 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 144 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 145 | +
|
| 146 | + Returns: |
| 147 | + Response[Union[HTTPValidationError, SimulationExperiment]] |
| 148 | + """ |
| 149 | + |
| 150 | + kwargs = _get_kwargs( |
| 151 | + body=body, |
| 152 | + tool_suite=tool_suite, |
| 153 | + ) |
| 154 | + |
| 155 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 156 | + |
| 157 | + return _build_response(client=client, response=response) |
| 158 | + |
| 159 | + |
| 160 | +async def asyncio( |
| 161 | + *, |
| 162 | + client: Union[AuthenticatedClient, Client], |
| 163 | + body: BodyExecuteSedml, |
| 164 | + tool_suite: ToolSuites, |
| 165 | +) -> Optional[Union[HTTPValidationError, SimulationExperiment]]: |
| 166 | + """Execute sedml |
| 167 | +
|
| 168 | + Args: |
| 169 | + tool_suite (ToolSuites): |
| 170 | + body (BodyExecuteSedml): |
| 171 | +
|
| 172 | + Raises: |
| 173 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 174 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 175 | +
|
| 176 | + Returns: |
| 177 | + Union[HTTPValidationError, SimulationExperiment] |
| 178 | + """ |
| 179 | + |
| 180 | + return ( |
| 181 | + await asyncio_detailed( |
| 182 | + client=client, |
| 183 | + body=body, |
| 184 | + tool_suite=tool_suite, |
| 185 | + ) |
| 186 | + ).parsed |
0 commit comments