1from typing import Any, Dict
2
3import httpx
4from retrying import retry
5
6from ...models.translate_native_quil_to_encrypted_binary_request import TranslateNativeQuilToEncryptedBinaryRequest
7from ...models.translate_native_quil_to_encrypted_binary_response import TranslateNativeQuilToEncryptedBinaryResponse
8from ...types import Response
9from ...util.errors import QCSHTTPStatusError, raise_for_status
10from ...util.retry import DEFAULT_RETRY_ARGUMENTS
11
12
13def _get_kwargs(
14    *,
15    quantum_processor_id: str,
16    json_body: TranslateNativeQuilToEncryptedBinaryRequest,
17) -> Dict[str, Any]:
18
19    json_json_body = json_body.to_dict()
20
21    return {
22        "json": json_json_body,
23    }
24
25
26def _parse_response(*, response: httpx.Response) -> TranslateNativeQuilToEncryptedBinaryResponse:
27    raise_for_status(response)
28    if response.status_code == 200:
29        response_200 = TranslateNativeQuilToEncryptedBinaryResponse.from_dict(response.json())
30
31        return response_200
32    else:
33        raise QCSHTTPStatusError(
34            f"Unexpected response: status code {response.status_code}", response=response, error=None
35        )
36
37
38def _build_response(*, response: httpx.Response) -> Response[TranslateNativeQuilToEncryptedBinaryResponse]:
39    """
40    Construct the Response class from the raw ``httpx.Response``.
41    """
42    return Response.build_from_httpx_response(response=response, parse_function=_parse_response)
43
44
45@retry(**DEFAULT_RETRY_ARGUMENTS)
46def sync(
47    *,
48    client: httpx.Client,
49    quantum_processor_id: str,
50    json_body: TranslateNativeQuilToEncryptedBinaryRequest,
51    httpx_request_kwargs: Dict[str, Any] = {},
52) -> Response[TranslateNativeQuilToEncryptedBinaryResponse]:
53    url = "/v1/quantumProcessors/{quantumProcessorId}:translateNativeQuilToEncryptedBinary".format(
54        quantumProcessorId=quantum_processor_id,
55    )
56
57    kwargs = _get_kwargs(
58        quantum_processor_id=quantum_processor_id,
59        json_body=json_body,
60    )
61    kwargs.update(httpx_request_kwargs)
62    response = client.request(
63        "post",
64        url,
65        **kwargs,
66    )
67    return _build_response(response=response)
68
69
70@retry(**DEFAULT_RETRY_ARGUMENTS)
71def sync_from_dict(
72    *,
73    client: httpx.Client,
74    quantum_processor_id: str,
75    json_body_dict: Dict,
76    httpx_request_kwargs: Dict[str, Any] = {},
77) -> Response[TranslateNativeQuilToEncryptedBinaryResponse]:
78    json_body = TranslateNativeQuilToEncryptedBinaryRequest.from_dict(json_body_dict)
79
80    url = "/v1/quantumProcessors/{quantumProcessorId}:translateNativeQuilToEncryptedBinary".format(
81        quantumProcessorId=quantum_processor_id,
82    )
83
84    kwargs = _get_kwargs(
85        quantum_processor_id=quantum_processor_id,
86        json_body=json_body,
87    )
88    kwargs.update(httpx_request_kwargs)
89    response = client.request(
90        "post",
91        url,
92        **kwargs,
93    )
94    return _build_response(response=response)
95
96
97@retry(**DEFAULT_RETRY_ARGUMENTS)
98async def asyncio(
99    *,
100    client: httpx.AsyncClient,
101    quantum_processor_id: str,
102    json_body: TranslateNativeQuilToEncryptedBinaryRequest,
103    httpx_request_kwargs: Dict[str, Any] = {},
104) -> Response[TranslateNativeQuilToEncryptedBinaryResponse]:
105    url = "/v1/quantumProcessors/{quantumProcessorId}:translateNativeQuilToEncryptedBinary".format(
106        quantumProcessorId=quantum_processor_id,
107    )
108
109    kwargs = _get_kwargs(
110        quantum_processor_id=quantum_processor_id,
111        json_body=json_body,
112    )
113    kwargs.update(httpx_request_kwargs)
114    response = await client.request(
115        "post",
116        url,
117        **kwargs,
118    )
119    return _build_response(response=response)
120
121
122@retry(**DEFAULT_RETRY_ARGUMENTS)
123async def asyncio_from_dict(
124    *,
125    client: httpx.AsyncClient,
126    quantum_processor_id: str,
127    json_body_dict: Dict,
128    httpx_request_kwargs: Dict[str, Any] = {},
129) -> Response[TranslateNativeQuilToEncryptedBinaryResponse]:
130    json_body = TranslateNativeQuilToEncryptedBinaryRequest.from_dict(json_body_dict)
131
132    url = "/v1/quantumProcessors/{quantumProcessorId}:translateNativeQuilToEncryptedBinary".format(
133        quantumProcessorId=quantum_processor_id,
134    )
135
136    kwargs = _get_kwargs(
137        quantum_processor_id=quantum_processor_id,
138        json_body=json_body,
139    )
140    kwargs.update(httpx_request_kwargs)
141    response = await client.request(
142        "post",
143        url,
144        **kwargs,
145    )
146    return _build_response(response=response)
147