88
99from copy import deepcopy
1010from typing import Any , TYPE_CHECKING , Union
11+ from typing_extensions import Self
1112
1213from azure .core import PipelineClient
1314from azure .core .credentials import AzureKeyCredential
1415from azure .core .pipeline import policies
1516from 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+ )
1924from ._serialization import Deserializer , Serializer
2025
2126if 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
0 commit comments