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