Skip to content

Commit 28c6a6e

Browse files
author
SDKAuto
committed
CodeGen from PR 31771 in Azure/azure-rest-api-specs
Merge 35efc4e0b0aa305211622d81c7b8fa5bf88dfe74 into 12492edbcf4c2d43d153da544ffbf1ffe7cbd20b
1 parent bf50574 commit 28c6a6e

36 files changed

+5850
-1353
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"commit": "440832a3e3a7e3acc50f423d95bc6a482ee79a72",
3+
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
4+
"typespec_src": "specification/cognitiveservices/ContentSafety",
5+
"@azure-tools/typespec-python": "0.37.2"
6+
}

sdk/contentsafety/azure-ai-contentsafety/azure/ai/contentsafety/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,32 @@
55
# Code generated by Microsoft (R) Python Code Generator.
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
8+
# pylint: disable=wrong-import-position
89

9-
from ._client import ContentSafetyClient
10-
from ._client import BlocklistClient
10+
from typing import TYPE_CHECKING
11+
12+
if TYPE_CHECKING:
13+
from ._patch import * # pylint: disable=unused-wildcard-import
14+
15+
from ._client import ContentSafetyClient # type: ignore
16+
from ._client import BlocklistClient # type: ignore
17+
from ._client import RaiPolicyClient # type: ignore
1118
from ._version import VERSION
1219

1320
__version__ = VERSION
1421

1522
try:
1623
from ._patch import __all__ as _patch_all
17-
from ._patch import * # pylint: disable=unused-wildcard-import
24+
from ._patch import *
1825
except ImportError:
1926
_patch_all = []
2027
from ._patch import patch_sdk as _patch_sdk
2128

2229
__all__ = [
2330
"ContentSafetyClient",
2431
"BlocklistClient",
32+
"RaiPolicyClient",
2533
]
26-
__all__.extend([p for p in _patch_all if p not in __all__])
34+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
2735

2836
_patch_sdk()

sdk/contentsafety/azure-ai-contentsafety/azure/ai/contentsafety/_client.py

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,38 @@
88

99
from copy import deepcopy
1010
from typing import Any, TYPE_CHECKING, Union
11+
from typing_extensions import Self
1112

1213
from azure.core import PipelineClient
1314
from azure.core.credentials import AzureKeyCredential
1415
from azure.core.pipeline import policies
1516
from azure.core.rest import HttpRequest, HttpResponse
1617

17-
from ._configuration import BlocklistClientConfiguration, ContentSafetyClientConfiguration
18-
from ._operations import BlocklistClientOperationsMixin, ContentSafetyClientOperationsMixin
18+
from ._configuration import BlocklistClientConfiguration, ContentSafetyClientConfiguration, RaiPolicyClientConfiguration
19+
from ._operations import (
20+
BlocklistClientOperationsMixin,
21+
ContentSafetyClientOperationsMixin,
22+
RaiPolicyClientOperationsMixin,
23+
)
1924
from ._serialization import Deserializer, Serializer
2025

2126
if TYPE_CHECKING:
22-
# pylint: disable=unused-import,ungrouped-imports
2327
from azure.core.credentials import TokenCredential
2428

2529

26-
class ContentSafetyClient(ContentSafetyClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
30+
class ContentSafetyClient(ContentSafetyClientOperationsMixin):
2731
"""ContentSafetyClient.
2832
2933
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
30-
https://:code:`<resource-name>`.cognitiveservices.azure.com). Required.
34+
https://\\\\ :code:`<resource-name>`.cognitiveservices.azure.com). Required.
3135
:type endpoint: str
32-
:param credential: Credential needed for the client to connect to Azure. Is either a
36+
:param credential: Credential used to authenticate requests to the service. Is either a
3337
AzureKeyCredential type or a TokenCredential type. Required.
3438
:type credential: ~azure.core.credentials.AzureKeyCredential or
3539
~azure.core.credentials.TokenCredential
36-
:keyword api_version: The API version to use for this operation. Default value is "2023-10-01".
37-
Note that overriding this default value may result in unsupported behavior.
40+
:keyword api_version: The API version to use for this operation. Default value is
41+
"2024-12-15-preview". Note that overriding this default value may result in unsupported
42+
behavior.
3843
:paramtype api_version: str
3944
"""
4045

@@ -84,7 +89,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
8489

8590
request_copy = deepcopy(request)
8691
path_format_arguments = {
87-
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
92+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str"),
8893
}
8994

9095
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
@@ -93,26 +98,27 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
9398
def close(self) -> None:
9499
self._client.close()
95100

96-
def __enter__(self) -> "ContentSafetyClient":
101+
def __enter__(self) -> Self:
97102
self._client.__enter__()
98103
return self
99104

100105
def __exit__(self, *exc_details: Any) -> None:
101106
self._client.__exit__(*exc_details)
102107

103108

104-
class BlocklistClient(BlocklistClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
109+
class BlocklistClient(BlocklistClientOperationsMixin):
105110
"""BlocklistClient.
106111
107112
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
108-
https://:code:`<resource-name>`.cognitiveservices.azure.com). Required.
113+
https://\\\\ :code:`<resource-name>`.cognitiveservices.azure.com). Required.
109114
:type endpoint: str
110-
:param credential: Credential needed for the client to connect to Azure. Is either a
115+
:param credential: Credential used to authenticate requests to the service. Is either a
111116
AzureKeyCredential type or a TokenCredential type. Required.
112117
:type credential: ~azure.core.credentials.AzureKeyCredential or
113118
~azure.core.credentials.TokenCredential
114-
:keyword api_version: The API version to use for this operation. Default value is "2023-10-01".
115-
Note that overriding this default value may result in unsupported behavior.
119+
:keyword api_version: The API version to use for this operation. Default value is
120+
"2024-12-15-preview". Note that overriding this default value may result in unsupported
121+
behavior.
116122
:paramtype api_version: str
117123
"""
118124

@@ -162,7 +168,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
162168

163169
request_copy = deepcopy(request)
164170
path_format_arguments = {
165-
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
171+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str"),
166172
}
167173

168174
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
@@ -171,7 +177,86 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
171177
def close(self) -> None:
172178
self._client.close()
173179

174-
def __enter__(self) -> "BlocklistClient":
180+
def __enter__(self) -> Self:
181+
self._client.__enter__()
182+
return self
183+
184+
def __exit__(self, *exc_details: Any) -> None:
185+
self._client.__exit__(*exc_details)
186+
187+
188+
class RaiPolicyClient(RaiPolicyClientOperationsMixin):
189+
"""RaiPolicyClient.
190+
191+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
192+
https://\\\\ :code:`<resource-name>`.cognitiveservices.azure.com). Required.
193+
:type endpoint: str
194+
:param credential: Credential used to authenticate requests to the service. Is either a
195+
AzureKeyCredential type or a TokenCredential type. Required.
196+
:type credential: ~azure.core.credentials.AzureKeyCredential or
197+
~azure.core.credentials.TokenCredential
198+
:keyword api_version: The API version to use for this operation. Default value is
199+
"2024-12-15-preview". Note that overriding this default value may result in unsupported
200+
behavior.
201+
:paramtype api_version: str
202+
"""
203+
204+
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
205+
_endpoint = "{endpoint}/contentsafety"
206+
self._config = RaiPolicyClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
207+
_policies = kwargs.pop("policies", None)
208+
if _policies is None:
209+
_policies = [
210+
policies.RequestIdPolicy(**kwargs),
211+
self._config.headers_policy,
212+
self._config.user_agent_policy,
213+
self._config.proxy_policy,
214+
policies.ContentDecodePolicy(**kwargs),
215+
self._config.redirect_policy,
216+
self._config.retry_policy,
217+
self._config.authentication_policy,
218+
self._config.custom_hook_policy,
219+
self._config.logging_policy,
220+
policies.DistributedTracingPolicy(**kwargs),
221+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
222+
self._config.http_logging_policy,
223+
]
224+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
225+
226+
self._serialize = Serializer()
227+
self._deserialize = Deserializer()
228+
self._serialize.client_side_validation = False
229+
230+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
231+
"""Runs the network request through the client's chained policies.
232+
233+
>>> from azure.core.rest import HttpRequest
234+
>>> request = HttpRequest("GET", "https://www.example.org/")
235+
<HttpRequest [GET], url: 'https://www.example.org/'>
236+
>>> response = client.send_request(request)
237+
<HttpResponse: 200 OK>
238+
239+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
240+
241+
:param request: The network request you want to make. Required.
242+
:type request: ~azure.core.rest.HttpRequest
243+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
244+
:return: The response of your network call. Does not do error handling on your response.
245+
:rtype: ~azure.core.rest.HttpResponse
246+
"""
247+
248+
request_copy = deepcopy(request)
249+
path_format_arguments = {
250+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str"),
251+
}
252+
253+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
254+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
255+
256+
def close(self) -> None:
257+
self._client.close()
258+
259+
def __enter__(self) -> Self:
175260
self._client.__enter__()
176261
return self
177262

sdk/contentsafety/azure-ai-contentsafety/azure/ai/contentsafety/_configuration.py

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@
1414
from ._version import VERSION
1515

1616
if TYPE_CHECKING:
17-
# pylint: disable=unused-import,ungrouped-imports
1817
from azure.core.credentials import TokenCredential
1918

2019

21-
class ContentSafetyClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
20+
class ContentSafetyClientConfiguration: # pylint: disable=too-many-instance-attributes
2221
"""Configuration for ContentSafetyClient.
2322
2423
Note that all parameters used to create this instance are saved as instance
2524
attributes.
2625
2726
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
28-
https://:code:`<resource-name>`.cognitiveservices.azure.com). Required.
27+
https://\\ :code:`<resource-name>`.cognitiveservices.azure.com). Required.
2928
:type endpoint: str
30-
:param credential: Credential needed for the client to connect to Azure. Is either a
29+
:param credential: Credential used to authenticate requests to the service. Is either a
3130
AzureKeyCredential type or a TokenCredential type. Required.
3231
:type credential: ~azure.core.credentials.AzureKeyCredential or
3332
~azure.core.credentials.TokenCredential
34-
:keyword api_version: The API version to use for this operation. Default value is "2023-10-01".
35-
Note that overriding this default value may result in unsupported behavior.
33+
:keyword api_version: The API version to use for this operation. Default value is
34+
"2024-12-15-preview". Note that overriding this default value may result in unsupported
35+
behavior.
3636
:paramtype api_version: str
3737
"""
3838

3939
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
40-
api_version: str = kwargs.pop("api_version", "2023-10-01")
40+
api_version: str = kwargs.pop("api_version", "2024-12-15-preview")
4141

4242
if endpoint is None:
4343
raise ValueError("Parameter 'endpoint' must not be None.")
@@ -73,26 +73,83 @@ def _configure(self, **kwargs: Any) -> None:
7373
self.authentication_policy = self._infer_policy(**kwargs)
7474

7575

76-
class BlocklistClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
76+
class BlocklistClientConfiguration: # pylint: disable=too-many-instance-attributes
7777
"""Configuration for BlocklistClient.
7878
7979
Note that all parameters used to create this instance are saved as instance
8080
attributes.
8181
8282
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
83-
https://:code:`<resource-name>`.cognitiveservices.azure.com). Required.
83+
https://\\ :code:`<resource-name>`.cognitiveservices.azure.com). Required.
8484
:type endpoint: str
85-
:param credential: Credential needed for the client to connect to Azure. Is either a
85+
:param credential: Credential used to authenticate requests to the service. Is either a
8686
AzureKeyCredential type or a TokenCredential type. Required.
8787
:type credential: ~azure.core.credentials.AzureKeyCredential or
8888
~azure.core.credentials.TokenCredential
89-
:keyword api_version: The API version to use for this operation. Default value is "2023-10-01".
90-
Note that overriding this default value may result in unsupported behavior.
89+
:keyword api_version: The API version to use for this operation. Default value is
90+
"2024-12-15-preview". Note that overriding this default value may result in unsupported
91+
behavior.
9192
:paramtype api_version: str
9293
"""
9394

9495
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
95-
api_version: str = kwargs.pop("api_version", "2023-10-01")
96+
api_version: str = kwargs.pop("api_version", "2024-12-15-preview")
97+
98+
if endpoint is None:
99+
raise ValueError("Parameter 'endpoint' must not be None.")
100+
if credential is None:
101+
raise ValueError("Parameter 'credential' must not be None.")
102+
103+
self.endpoint = endpoint
104+
self.credential = credential
105+
self.api_version = api_version
106+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"])
107+
kwargs.setdefault("sdk_moniker", "ai-contentsafety/{}".format(VERSION))
108+
self.polling_interval = kwargs.get("polling_interval", 30)
109+
self._configure(**kwargs)
110+
111+
def _infer_policy(self, **kwargs):
112+
if isinstance(self.credential, AzureKeyCredential):
113+
return policies.AzureKeyCredentialPolicy(self.credential, "Ocp-Apim-Subscription-Key", **kwargs)
114+
if hasattr(self.credential, "get_token"):
115+
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
116+
raise TypeError(f"Unsupported credential: {self.credential}")
117+
118+
def _configure(self, **kwargs: Any) -> None:
119+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
120+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
121+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
122+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
123+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
124+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
125+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
126+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
127+
self.authentication_policy = kwargs.get("authentication_policy")
128+
if self.credential and not self.authentication_policy:
129+
self.authentication_policy = self._infer_policy(**kwargs)
130+
131+
132+
class RaiPolicyClientConfiguration: # pylint: disable=too-many-instance-attributes
133+
"""Configuration for RaiPolicyClient.
134+
135+
Note that all parameters used to create this instance are saved as instance
136+
attributes.
137+
138+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
139+
https://\\ :code:`<resource-name>`.cognitiveservices.azure.com). Required.
140+
:type endpoint: str
141+
:param credential: Credential used to authenticate requests to the service. Is either a
142+
AzureKeyCredential type or a TokenCredential type. Required.
143+
:type credential: ~azure.core.credentials.AzureKeyCredential or
144+
~azure.core.credentials.TokenCredential
145+
:keyword api_version: The API version to use for this operation. Default value is
146+
"2024-12-15-preview". Note that overriding this default value may result in unsupported
147+
behavior.
148+
:paramtype api_version: str
149+
"""
150+
151+
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
152+
api_version: str = kwargs.pop("api_version", "2024-12-15-preview")
96153

97154
if endpoint is None:
98155
raise ValueError("Parameter 'endpoint' must not be None.")

0 commit comments

Comments
 (0)