|
| 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) AutoRest Code Generator. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
| 7 | +# -------------------------------------------------------------------------- |
| 8 | +from collections.abc import MutableMapping |
| 9 | +from io import IOBase |
| 10 | +from typing import Any, Callable, IO, Optional, TypeVar, Union, overload |
| 11 | + |
| 12 | +from azure.core import AsyncPipelineClient |
| 13 | +from azure.core.exceptions import ( |
| 14 | + ClientAuthenticationError, |
| 15 | + HttpResponseError, |
| 16 | + ResourceExistsError, |
| 17 | + ResourceNotFoundError, |
| 18 | + ResourceNotModifiedError, |
| 19 | + map_error, |
| 20 | +) |
| 21 | +from azure.core.pipeline import PipelineResponse |
| 22 | +from azure.core.rest import AsyncHttpResponse, HttpRequest |
| 23 | +from azure.core.tracing.decorator_async import distributed_trace_async |
| 24 | +from azure.core.utils import case_insensitive_dict |
| 25 | +from azure.mgmt.core.exceptions import ARMErrorFormat |
| 26 | + |
| 27 | +from ..._utils.serialization import Deserializer, Serializer |
| 28 | +from ...operations._operations import build_list_request |
| 29 | +from .._configuration import PyprojectMgmtClientConfiguration |
| 30 | + |
| 31 | +List = list |
| 32 | +T = TypeVar("T") |
| 33 | +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] |
| 34 | + |
| 35 | + |
| 36 | +class Operations: |
| 37 | + """ |
| 38 | + .. warning:: |
| 39 | + **DO NOT** instantiate this class directly. |
| 40 | +
|
| 41 | + Instead, you should access the following operations through |
| 42 | + :class:`~azure.mgmt.pyproject.aio.PyprojectMgmtClient`'s |
| 43 | + :attr:`operations` attribute. |
| 44 | + """ |
| 45 | + |
| 46 | + def __init__(self, *args, **kwargs) -> None: |
| 47 | + input_args = list(args) |
| 48 | + self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") |
| 49 | + self._config: PyprojectMgmtClientConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") |
| 50 | + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") |
| 51 | + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") |
| 52 | + |
| 53 | + @overload |
| 54 | + async def list(self, body: List[str], *, content_type: str = "application/json", **kwargs: Any) -> None: |
| 55 | + """Process list of strings. |
| 56 | +
|
| 57 | + Processes a list of strings with no return value. |
| 58 | +
|
| 59 | + :param body: List of strings to process. Required. |
| 60 | + :type body: list[str] |
| 61 | + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. |
| 62 | + Default value is "application/json". |
| 63 | + :paramtype content_type: str |
| 64 | + :return: None or the result of cls(response) |
| 65 | + :rtype: None |
| 66 | + :raises ~azure.core.exceptions.HttpResponseError: |
| 67 | + """ |
| 68 | + |
| 69 | + @overload |
| 70 | + async def list(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None: |
| 71 | + """Process list of strings. |
| 72 | +
|
| 73 | + Processes a list of strings with no return value. |
| 74 | +
|
| 75 | + :param body: List of strings to process. Required. |
| 76 | + :type body: IO[bytes] |
| 77 | + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. |
| 78 | + Default value is "application/json". |
| 79 | + :paramtype content_type: str |
| 80 | + :return: None or the result of cls(response) |
| 81 | + :rtype: None |
| 82 | + :raises ~azure.core.exceptions.HttpResponseError: |
| 83 | + """ |
| 84 | + |
| 85 | + @distributed_trace_async |
| 86 | + async def list(self, body: Union[List[str], IO[bytes]], **kwargs: Any) -> None: |
| 87 | + """Process list of strings. |
| 88 | +
|
| 89 | + Processes a list of strings with no return value. |
| 90 | +
|
| 91 | + :param body: List of strings to process. Is either a [str] type or a IO[bytes] type. Required. |
| 92 | + :type body: list[str] or IO[bytes] |
| 93 | + :return: None or the result of cls(response) |
| 94 | + :rtype: None |
| 95 | + :raises ~azure.core.exceptions.HttpResponseError: |
| 96 | + """ |
| 97 | + error_map: MutableMapping = { |
| 98 | + 401: ClientAuthenticationError, |
| 99 | + 404: ResourceNotFoundError, |
| 100 | + 409: ResourceExistsError, |
| 101 | + 304: ResourceNotModifiedError, |
| 102 | + } |
| 103 | + error_map.update(kwargs.pop("error_map", {}) or {}) |
| 104 | + |
| 105 | + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) |
| 106 | + _params = kwargs.pop("params", {}) or {} |
| 107 | + |
| 108 | + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) |
| 109 | + cls: ClsType[None] = kwargs.pop("cls", None) |
| 110 | + |
| 111 | + content_type = content_type or "application/json" |
| 112 | + _json = None |
| 113 | + _content = None |
| 114 | + if isinstance(body, (IOBase, bytes)): |
| 115 | + _content = body |
| 116 | + else: |
| 117 | + _json = self._serialize.body(body, "[str]") |
| 118 | + |
| 119 | + _request = build_list_request( |
| 120 | + content_type=content_type, |
| 121 | + json=_json, |
| 122 | + content=_content, |
| 123 | + headers=_headers, |
| 124 | + params=_params, |
| 125 | + ) |
| 126 | + _request.url = self._client.format_url(_request.url) |
| 127 | + |
| 128 | + _stream = False |
| 129 | + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access |
| 130 | + _request, stream=_stream, **kwargs |
| 131 | + ) |
| 132 | + |
| 133 | + response = pipeline_response.http_response |
| 134 | + |
| 135 | + if response.status_code not in [204]: |
| 136 | + map_error(status_code=response.status_code, response=response, error_map=error_map) |
| 137 | + raise HttpResponseError(response=response, error_format=ARMErrorFormat) |
| 138 | + |
| 139 | + if cls: |
| 140 | + return cls(pipeline_response, None, {}) # type: ignore |
0 commit comments