|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any, Dict, Optional, Union |
| 3 | + |
| 4 | +import httpx |
| 5 | + |
| 6 | +from ... import errors |
| 7 | +from ...client import Client |
| 8 | +from ...models.computation import Computation |
| 9 | +from ...models.error import Error |
| 10 | +from ...types import UNSET, Response, Unset |
| 11 | + |
| 12 | + |
| 13 | +def _get_kwargs( |
| 14 | + computation_id: str, |
| 15 | + *, |
| 16 | + client: Client, |
| 17 | + notify_end: Union[Unset, None, bool] = UNSET, |
| 18 | +) -> Dict[str, Any]: |
| 19 | + url = "{}/computation/{computationId}".format(client.base_url, computationId=computation_id) |
| 20 | + |
| 21 | + headers: Dict[str, str] = client.get_headers() |
| 22 | + cookies: Dict[str, Any] = client.get_cookies() |
| 23 | + |
| 24 | + params: Dict[str, Any] = {} |
| 25 | + params["notifyEnd"] = notify_end |
| 26 | + |
| 27 | + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} |
| 28 | + |
| 29 | + # Set the proxies if the client has proxies set. |
| 30 | + proxies = None |
| 31 | + if hasattr(client, "proxies") and client.proxies is not None: |
| 32 | + https_proxy = client.proxies.get("https://") |
| 33 | + if https_proxy: |
| 34 | + proxies = https_proxy |
| 35 | + else: |
| 36 | + http_proxy = client.proxies.get("http://") |
| 37 | + if http_proxy: |
| 38 | + proxies = http_proxy |
| 39 | + |
| 40 | + return { |
| 41 | + "method": "patch", |
| 42 | + "url": url, |
| 43 | + "headers": headers, |
| 44 | + "cookies": cookies, |
| 45 | + "timeout": client.get_timeout(), |
| 46 | + "proxies": proxies, |
| 47 | + "params": params, |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Computation, Error]]: |
| 52 | + if response.status_code == HTTPStatus.OK: |
| 53 | + response_200 = Computation.from_dict(response.json()) |
| 54 | + |
| 55 | + return response_200 |
| 56 | + if response.status_code == HTTPStatus.FORBIDDEN: |
| 57 | + response_403 = Error.from_dict(response.json()) |
| 58 | + |
| 59 | + return response_403 |
| 60 | + if response.status_code == HTTPStatus.NOT_FOUND: |
| 61 | + response_404 = Error.from_dict(response.json()) |
| 62 | + |
| 63 | + return response_404 |
| 64 | + if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: |
| 65 | + response_500 = Error.from_dict(response.json()) |
| 66 | + |
| 67 | + return response_500 |
| 68 | + if client.raise_on_unexpected_status: |
| 69 | + raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code} ({response})") |
| 70 | + else: |
| 71 | + return None |
| 72 | + |
| 73 | + |
| 74 | +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Computation, Error]]: |
| 75 | + return Response( |
| 76 | + status_code=HTTPStatus(response.status_code), |
| 77 | + content=response.content, |
| 78 | + headers=response.headers, |
| 79 | + parsed=_parse_response(client=client, response=response), |
| 80 | + ) |
| 81 | + |
| 82 | + |
| 83 | +def sync_detailed( |
| 84 | + computation_id: str, |
| 85 | + *, |
| 86 | + client: Client, |
| 87 | + notify_end: Union[Unset, None, bool] = UNSET, |
| 88 | +) -> Response[Union[Computation, Error]]: |
| 89 | + """Modify editable attributes from a computation. |
| 90 | +
|
| 91 | + Args: |
| 92 | + computation_id (str): |
| 93 | + notify_end (Union[Unset, None, bool]): |
| 94 | +
|
| 95 | + Raises: |
| 96 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 97 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 98 | +
|
| 99 | + Returns: |
| 100 | + Response[Union[Computation, Error]] |
| 101 | + """ |
| 102 | + |
| 103 | + kwargs = _get_kwargs( |
| 104 | + computation_id=computation_id, |
| 105 | + client=client, |
| 106 | + notify_end=notify_end, |
| 107 | + ) |
| 108 | + |
| 109 | + response = httpx.request( |
| 110 | + verify=client.verify_ssl, |
| 111 | + **kwargs, |
| 112 | + ) |
| 113 | + |
| 114 | + return _build_response(client=client, response=response) |
| 115 | + |
| 116 | + |
| 117 | +def sync( |
| 118 | + computation_id: str, |
| 119 | + *, |
| 120 | + client: Client, |
| 121 | + notify_end: Union[Unset, None, bool] = UNSET, |
| 122 | +) -> Optional[Union[Computation, Error]]: |
| 123 | + """Modify editable attributes from a computation. |
| 124 | +
|
| 125 | + Args: |
| 126 | + computation_id (str): |
| 127 | + notify_end (Union[Unset, None, bool]): |
| 128 | +
|
| 129 | + Raises: |
| 130 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 131 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 132 | +
|
| 133 | + Returns: |
| 134 | + Response[Union[Computation, Error]] |
| 135 | + """ |
| 136 | + |
| 137 | + return sync_detailed( |
| 138 | + computation_id=computation_id, |
| 139 | + client=client, |
| 140 | + notify_end=notify_end, |
| 141 | + ).parsed |
| 142 | + |
| 143 | + |
| 144 | +async def asyncio_detailed( |
| 145 | + computation_id: str, |
| 146 | + *, |
| 147 | + client: Client, |
| 148 | + notify_end: Union[Unset, None, bool] = UNSET, |
| 149 | +) -> Response[Union[Computation, Error]]: |
| 150 | + """Modify editable attributes from a computation. |
| 151 | +
|
| 152 | + Args: |
| 153 | + computation_id (str): |
| 154 | + notify_end (Union[Unset, None, bool]): |
| 155 | +
|
| 156 | + Raises: |
| 157 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 158 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 159 | +
|
| 160 | + Returns: |
| 161 | + Response[Union[Computation, Error]] |
| 162 | + """ |
| 163 | + |
| 164 | + kwargs = _get_kwargs( |
| 165 | + computation_id=computation_id, |
| 166 | + client=client, |
| 167 | + notify_end=notify_end, |
| 168 | + ) |
| 169 | + |
| 170 | + async with httpx.AsyncClient(verify=client.verify_ssl) as _client: |
| 171 | + response = await _client.request(**kwargs) |
| 172 | + |
| 173 | + return _build_response(client=client, response=response) |
| 174 | + |
| 175 | + |
| 176 | +async def asyncio( |
| 177 | + computation_id: str, |
| 178 | + *, |
| 179 | + client: Client, |
| 180 | + notify_end: Union[Unset, None, bool] = UNSET, |
| 181 | +) -> Optional[Union[Computation, Error]]: |
| 182 | + """Modify editable attributes from a computation. |
| 183 | +
|
| 184 | + Args: |
| 185 | + computation_id (str): |
| 186 | + notify_end (Union[Unset, None, bool]): |
| 187 | +
|
| 188 | + Raises: |
| 189 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 190 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 191 | +
|
| 192 | + Returns: |
| 193 | + Response[Union[Computation, Error]] |
| 194 | + """ |
| 195 | + |
| 196 | + return ( |
| 197 | + await asyncio_detailed( |
| 198 | + computation_id=computation_id, |
| 199 | + client=client, |
| 200 | + notify_end=notify_end, |
| 201 | + ) |
| 202 | + ).parsed |
0 commit comments