|
| 1 | +from dataclasses import asdict |
| 2 | +from typing import Any, Dict, List, Optional, Union, cast |
| 3 | + |
| 4 | +import httpx |
| 5 | + |
| 6 | +from ...client import AuthenticatedClient, Client |
| 7 | +from ...types import Response |
| 8 | + |
| 9 | + |
| 10 | +def _get_kwargs( |
| 11 | + *, |
| 12 | + client: Client, |
| 13 | +) -> Dict[str, Any]: |
| 14 | + url = "{}/tests/basic_lists/floats".format(client.base_url) |
| 15 | + |
| 16 | + headers: Dict[str, Any] = client.get_headers() |
| 17 | + |
| 18 | + return { |
| 19 | + "url": url, |
| 20 | + "headers": headers, |
| 21 | + "cookies": client.get_cookies(), |
| 22 | + "timeout": client.get_timeout(), |
| 23 | + } |
| 24 | + |
| 25 | + |
| 26 | +def _parse_response(*, response: httpx.Response) -> Optional[List[float]]: |
| 27 | + if response.status_code == 200: |
| 28 | + return [float(item) for item in cast(List[float], response.json())] |
| 29 | + return None |
| 30 | + |
| 31 | + |
| 32 | +def _build_response(*, response: httpx.Response) -> Response[List[float]]: |
| 33 | + return Response( |
| 34 | + status_code=response.status_code, |
| 35 | + content=response.content, |
| 36 | + headers=response.headers, |
| 37 | + parsed=_parse_response(response=response), |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +def sync_detailed( |
| 42 | + *, |
| 43 | + client: Client, |
| 44 | +) -> Response[List[float]]: |
| 45 | + kwargs = _get_kwargs( |
| 46 | + client=client, |
| 47 | + ) |
| 48 | + |
| 49 | + response = httpx.get( |
| 50 | + **kwargs, |
| 51 | + ) |
| 52 | + |
| 53 | + return _build_response(response=response) |
| 54 | + |
| 55 | + |
| 56 | +def sync( |
| 57 | + *, |
| 58 | + client: Client, |
| 59 | +) -> Optional[List[float]]: |
| 60 | + """ Get a list of floats """ |
| 61 | + |
| 62 | + return sync_detailed( |
| 63 | + client=client, |
| 64 | + ).parsed |
| 65 | + |
| 66 | + |
| 67 | +async def asyncio_detailed( |
| 68 | + *, |
| 69 | + client: Client, |
| 70 | +) -> Response[List[float]]: |
| 71 | + kwargs = _get_kwargs( |
| 72 | + client=client, |
| 73 | + ) |
| 74 | + |
| 75 | + async with httpx.AsyncClient() as _client: |
| 76 | + response = await _client.get(**kwargs) |
| 77 | + |
| 78 | + return _build_response(response=response) |
| 79 | + |
| 80 | + |
| 81 | +async def asyncio( |
| 82 | + *, |
| 83 | + client: Client, |
| 84 | +) -> Optional[List[float]]: |
| 85 | + """ Get a list of floats """ |
| 86 | + |
| 87 | + return ( |
| 88 | + await asyncio_detailed( |
| 89 | + client=client, |
| 90 | + ) |
| 91 | + ).parsed |
0 commit comments