|
| 1 | +# coding=utf-8 |
| 2 | +# -------------------------------------------------------------------------- |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | +# Code generated by Microsoft (R) Python Code Generator. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
| 7 | +# -------------------------------------------------------------------------- |
| 8 | + |
| 9 | +from copy import deepcopy |
| 10 | +from typing import Any, TYPE_CHECKING, Union |
| 11 | +from typing_extensions import Self |
| 12 | + |
| 13 | +from azure.core import PipelineClient |
| 14 | +from azure.core.credentials import AzureKeyCredential |
| 15 | +from azure.core.pipeline import policies |
| 16 | +from azure.core.rest import HttpRequest, HttpResponse |
| 17 | + |
| 18 | +from ._configuration import WorkspaceClientConfiguration |
| 19 | +from ._utils.serialization import Deserializer, Serializer |
| 20 | +from .operations import ServicesOperations |
| 21 | + |
| 22 | +if TYPE_CHECKING: |
| 23 | + from azure.core.credentials import TokenCredential |
| 24 | + |
| 25 | + |
| 26 | +class WorkspaceClient: |
| 27 | + """Azure Quantum Workspace Services. |
| 28 | +
|
| 29 | + :ivar services: ServicesOperations operations |
| 30 | + :vartype services: azure.quantum.operations.ServicesOperations |
| 31 | + :param region: The Azure region where the Azure Quantum Workspace is located. Required. |
| 32 | + :type region: str |
| 33 | + :param credential: Credential used to authenticate requests to the service. Is either a token |
| 34 | + credential type or a key credential type. Required. |
| 35 | + :type credential: ~azure.core.credentials.TokenCredential or |
| 36 | + ~azure.core.credentials.AzureKeyCredential |
| 37 | + :keyword service_base_url: The Azure Quantum service base url. Default value is |
| 38 | + "quantum.azure.com". |
| 39 | + :paramtype service_base_url: str |
| 40 | + :keyword api_version: The API version to use for this operation. Default value is |
| 41 | + "2024-10-01-preview". Note that overriding this default value may result in unsupported |
| 42 | + behavior. |
| 43 | + :paramtype api_version: str |
| 44 | + """ |
| 45 | + |
| 46 | + def __init__( |
| 47 | + self, |
| 48 | + region: str, |
| 49 | + credential: Union["TokenCredential", AzureKeyCredential], |
| 50 | + *, |
| 51 | + service_base_url: str = "quantum.azure.com", |
| 52 | + **kwargs: Any |
| 53 | + ) -> None: |
| 54 | + _endpoint = "https://{region}.{serviceBaseUrl}" |
| 55 | + self._config = WorkspaceClientConfiguration( |
| 56 | + region=region, credential=credential, service_base_url=service_base_url, **kwargs |
| 57 | + ) |
| 58 | + |
| 59 | + _policies = kwargs.pop("policies", None) |
| 60 | + if _policies is None: |
| 61 | + _policies = [ |
| 62 | + policies.RequestIdPolicy(**kwargs), |
| 63 | + self._config.headers_policy, |
| 64 | + self._config.user_agent_policy, |
| 65 | + self._config.proxy_policy, |
| 66 | + policies.ContentDecodePolicy(**kwargs), |
| 67 | + self._config.redirect_policy, |
| 68 | + self._config.retry_policy, |
| 69 | + self._config.authentication_policy, |
| 70 | + self._config.custom_hook_policy, |
| 71 | + self._config.logging_policy, |
| 72 | + policies.DistributedTracingPolicy(**kwargs), |
| 73 | + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, |
| 74 | + self._config.http_logging_policy, |
| 75 | + ] |
| 76 | + self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) |
| 77 | + |
| 78 | + self._serialize = Serializer() |
| 79 | + self._deserialize = Deserializer() |
| 80 | + self._serialize.client_side_validation = False |
| 81 | + self.services = ServicesOperations(self._client, self._config, self._serialize, self._deserialize) |
| 82 | + |
| 83 | + def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: |
| 84 | + """Runs the network request through the client's chained policies. |
| 85 | +
|
| 86 | + >>> from azure.core.rest import HttpRequest |
| 87 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 88 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 89 | + >>> response = client.send_request(request) |
| 90 | + <HttpResponse: 200 OK> |
| 91 | +
|
| 92 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 93 | +
|
| 94 | + :param request: The network request you want to make. Required. |
| 95 | + :type request: ~azure.core.rest.HttpRequest |
| 96 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
| 97 | + :return: The response of your network call. Does not do error handling on your response. |
| 98 | + :rtype: ~azure.core.rest.HttpResponse |
| 99 | + """ |
| 100 | + |
| 101 | + request_copy = deepcopy(request) |
| 102 | + path_format_arguments = { |
| 103 | + "region": self._serialize.url("self._config.region", self._config.region, "str"), |
| 104 | + "serviceBaseUrl": self._serialize.url( |
| 105 | + "self._config.service_base_url", self._config.service_base_url, "str" |
| 106 | + ), |
| 107 | + } |
| 108 | + |
| 109 | + request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) |
| 110 | + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore |
| 111 | + |
| 112 | + def close(self) -> None: |
| 113 | + self._client.close() |
| 114 | + |
| 115 | + def __enter__(self) -> Self: |
| 116 | + self._client.__enter__() |
| 117 | + return self |
| 118 | + |
| 119 | + def __exit__(self, *exc_details: Any) -> None: |
| 120 | + self._client.__exit__(*exc_details) |
0 commit comments