77import json
88from typing import Any , TYPE_CHECKING , List , Union , overload
99from azure .core .tracing .decorator import distributed_trace
10- from ._generated import BatchDocumentTranslationClient as _BatchDocumentTranslationClient
10+ from ._generated import (
11+ BatchDocumentTranslationClient as _BatchDocumentTranslationClient ,
12+ )
1113from ._models import (
1214 TranslationStatusResult ,
1315 DocumentStatusResult ,
1416 DocumentTranslationInput ,
15- FileFormat
17+ FileFormat ,
1618)
1719from ._user_agent import USER_AGENT
1820from ._polling import TranslationPolling , DocumentTranslationLROPollingMethod
2123 convert_datetime ,
2224 get_authentication_policy ,
2325 get_translation_input ,
24- POLLING_INTERVAL
26+ POLLING_INTERVAL ,
2527)
28+
2629if TYPE_CHECKING :
2730 from azure .core .paging import ItemPaged
2831 from azure .core .credentials import TokenCredential , AzureKeyCredential
2932 from ._polling import DocumentTranslationLROPoller
3033
3134
3235class DocumentTranslationClient (object ): # pylint: disable=r0205
33-
3436 def __init__ (self , endpoint , credential , ** kwargs ):
3537 # type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None
3638 """DocumentTranslationClient is your interface to the Document Translation service.
@@ -67,7 +69,7 @@ def __init__(self, endpoint, credential, **kwargs):
6769 """
6870 self ._endpoint = endpoint
6971 self ._credential = credential
70- self ._api_version = kwargs .pop (' api_version' , None )
72+ self ._api_version = kwargs .pop (" api_version" , None )
7173
7274 authentication_policy = get_authentication_policy (credential )
7375 polling_interval = kwargs .pop ("polling_interval" , POLLING_INTERVAL )
@@ -98,19 +100,22 @@ def close(self):
98100
99101 @overload
100102 def begin_translation (self , source_url , target_url , target_language_code , ** kwargs ):
101- # type: (str, str, str, **Any) -> DocumentTranslationPoller [ItemPaged[DocumentStatusResult]]
103+ # type: (str, str, str, **Any) -> DocumentTranslationLROPoller [ItemPaged[DocumentStatusResult]]
102104 pass
103105
104106 @overload
105107 def begin_translation (self , inputs , ** kwargs ):
106108 # type: (List[DocumentTranslationInput], **Any) -> DocumentTranslationLROPoller[ItemPaged[DocumentStatusResult]]
107109 pass
108110
109- def begin_translation (self , * args , ** kwargs ): # pylint: disable=client-method-missing-type-annotations
111+ def begin_translation (
112+ self , * args , ** kwargs
113+ ): # pylint: disable=client-method-missing-type-annotations
110114 """Begin translating the document(s) in your source container to your target container
111115 in the given language. To perform a single translation from source to target, pass the `source_url`,
112116 `target_url`, and `target_language_code` parameters. To pass multiple inputs for translation, including
113- other translation options, pass the `inputs` parameter as a list of DocumentTranslationInput.
117+ other translation options, pass the `inputs` parameter as a list of
118+ :class:`~azure.ai.translation.document.DocumentTranslationInput`.
114119
115120 For supported languages and document formats, see the service documentation:
116121 https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview
@@ -153,7 +158,8 @@ def deserialization_callback(
153158 return self .list_all_document_statuses (translation_status ["id" ])
154159
155160 polling_interval = kwargs .pop (
156- "polling_interval" , self ._client ._config .polling_interval # pylint: disable=protected-access
161+ "polling_interval" ,
162+ self ._client ._config .polling_interval , # pylint: disable=protected-access
157163 )
158164
159165 pipeline_response = None
@@ -168,11 +174,10 @@ def deserialization_callback(
168174 inputs = inputs if not continuation_token else None ,
169175 polling = DocumentTranslationLROPollingMethod (
170176 timeout = polling_interval ,
171- lro_algorithms = [
172- TranslationPolling ()
173- ],
177+ lro_algorithms = [TranslationPolling ()],
174178 cont_token_response = pipeline_response ,
175- ** kwargs ),
179+ ** kwargs
180+ ),
176181 cls = callback ,
177182 continuation_token = continuation_token ,
178183 ** kwargs
@@ -192,8 +197,12 @@ def get_translation_status(self, translation_id, **kwargs):
192197 :raises ~azure.core.exceptions.HttpResponseError or ~azure.core.exceptions.ResourceNotFoundError:
193198 """
194199
195- translation_status = self ._client .document_translation .get_translation_status (translation_id , ** kwargs )
196- return TranslationStatusResult ._from_generated (translation_status ) # pylint: disable=protected-access
200+ translation_status = self ._client .document_translation .get_translation_status (
201+ translation_id , ** kwargs
202+ )
203+ return TranslationStatusResult ._from_generated ( # pylint: disable=protected-access
204+ translation_status
205+ )
197206
198207 @distributed_trace
199208 def cancel_translation (self , translation_id , ** kwargs ):
@@ -223,13 +232,15 @@ def list_all_translation_statuses(self, **kwargs):
223232 :keyword int results_per_page: is the number of operations returned per page.
224233 :keyword list[str] translation_ids: translation operations ids to filter by.
225234 :keyword list[str] statuses: translation operation statuses to filter by.
226- :keyword Union[str, datetime.datetime] created_after: get operations created after certain datetime.
227- :keyword Union[str, datetime.datetime] created_before: get operations created before certain datetime.
235+ :keyword created_after: get operations created after certain datetime.
236+ :paramtype created_after: Union[str, datetime.datetime]
237+ :keyword created_before: get operations created before certain datetime.
238+ :paramtype created_before: Union[str, datetime.datetime]
228239 :keyword list[str] order_by: the sorting query for the operations returned.
229240 format: ["parm1 asc/desc", "parm2 asc/desc", ...]
230241 (ex: 'createdDateTimeUtc asc', 'createdDateTimeUtc desc').
231- :return: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document. TranslationStatusResult`]
232- :rtype: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document. TranslationStatusResult` ]
242+ :return: A pageable of TranslationStatusResult.
243+ :rtype: ~azure.core.paging.ItemPaged[TranslationStatusResult]
233244 :raises ~azure.core.exceptions.HttpResponseError:
234245
235246 .. admonition:: Example:
@@ -248,14 +259,19 @@ def list_all_translation_statuses(self, **kwargs):
248259 results_per_page = kwargs .pop ("results_per_page" , None )
249260 translation_ids = kwargs .pop ("translation_ids" , None )
250261
251- def _convert_from_generated_model (generated_model ): # pylint: disable=protected-access
252- return TranslationStatusResult ._from_generated (generated_model ) # pylint: disable=protected-access
262+ def _convert_from_generated_model (
263+ generated_model ,
264+ ): # pylint: disable=protected-access
265+ return TranslationStatusResult ._from_generated (
266+ generated_model
267+ ) # pylint: disable=protected-access
253268
254269 model_conversion_function = kwargs .pop (
255270 "cls" ,
256271 lambda translation_statuses : [
257272 _convert_from_generated_model (status ) for status in translation_statuses
258- ])
273+ ],
274+ )
259275
260276 return self ._client .document_translation .get_translations_status (
261277 cls = model_conversion_function ,
@@ -278,13 +294,15 @@ def list_all_document_statuses(self, translation_id, **kwargs):
278294 :keyword int results_per_page: is the number of documents returned per page.
279295 :keyword list[str] document_ids: document IDs to filter by.
280296 :keyword list[str] statuses: document statuses to filter by.
281- :keyword Union[str, datetime.datetime] translated_after: get document translated after certain datetime.
282- :keyword Union[str, datetime.datetime] translated_before: get document translated before certain datetime.
297+ :keyword translated_after: get document translated after certain datetime.
298+ :paramtype translated_after: Union[str, datetime.datetime]
299+ :keyword translated_before: get document translated before certain datetime.
300+ :paramtype translated_before: Union[str, datetime.datetime]
283301 :keyword list[str] order_by: the sorting query for the documents.
284302 format: ["parm1 asc/desc", "parm2 asc/desc", ...]
285303 (ex: 'createdDateTimeUtc asc', 'createdDateTimeUtc desc').
286- :return: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document. DocumentStatusResult`]
287- :rtype: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document. DocumentStatusResult` ]
304+ :return: A pageable of DocumentStatusResult.
305+ :rtype: ~azure.core.paging.ItemPaged[DocumentStatusResult]
288306 :raises ~azure.core.exceptions.HttpResponseError:
289307
290308 .. admonition:: Example:
@@ -298,20 +316,26 @@ def list_all_document_statuses(self, translation_id, **kwargs):
298316 """
299317 translated_after = kwargs .pop ("translated_after" , None )
300318 translated_before = kwargs .pop ("translated_before" , None )
301- translated_after = convert_datetime (translated_after ) if translated_after else None
302- translated_before = convert_datetime (translated_before ) if translated_before else None
319+ translated_after = (
320+ convert_datetime (translated_after ) if translated_after else None
321+ )
322+ translated_before = (
323+ convert_datetime (translated_before ) if translated_before else None
324+ )
303325 results_per_page = kwargs .pop ("results_per_page" , None )
304326 document_ids = kwargs .pop ("document_ids" , None )
305327
306-
307328 def _convert_from_generated_model (generated_model ):
308- return DocumentStatusResult ._from_generated (generated_model ) # pylint: disable=protected-access
329+ return DocumentStatusResult ._from_generated ( # pylint: disable=protected-access
330+ generated_model
331+ )
309332
310333 model_conversion_function = kwargs .pop (
311334 "cls" ,
312335 lambda doc_statuses : [
313336 _convert_from_generated_model (doc_status ) for doc_status in doc_statuses
314- ])
337+ ],
338+ )
315339
316340 return self ._client .document_translation .get_documents_status (
317341 id = translation_id ,
@@ -336,10 +360,11 @@ def get_document_status(self, translation_id, document_id, **kwargs):
336360 """
337361
338362 document_status = self ._client .document_translation .get_document_status (
339- translation_id ,
340- document_id ,
341- ** kwargs )
342- return DocumentStatusResult ._from_generated (document_status ) # pylint: disable=protected-access
363+ translation_id , document_id , ** kwargs
364+ )
365+ return DocumentStatusResult ._from_generated ( # pylint: disable=protected-access
366+ document_status
367+ )
343368
344369 @distributed_trace
345370 def get_glossary_formats (self , ** kwargs ):
@@ -351,8 +376,12 @@ def get_glossary_formats(self, **kwargs):
351376 :raises ~azure.core.exceptions.HttpResponseError:
352377 """
353378
354- glossary_formats = self ._client .document_translation .get_supported_glossary_formats (** kwargs )
355- return FileFormat ._from_generated_list (glossary_formats .value ) # pylint: disable=protected-access
379+ glossary_formats = (
380+ self ._client .document_translation .get_supported_glossary_formats (** kwargs )
381+ )
382+ return FileFormat ._from_generated_list ( # pylint: disable=protected-access
383+ glossary_formats .value
384+ )
356385
357386 @distributed_trace
358387 def get_document_formats (self , ** kwargs ):
@@ -364,5 +393,9 @@ def get_document_formats(self, **kwargs):
364393 :raises ~azure.core.exceptions.HttpResponseError:
365394 """
366395
367- document_formats = self ._client .document_translation .get_supported_document_formats (** kwargs )
368- return FileFormat ._from_generated_list (document_formats .value ) # pylint: disable=protected-access
396+ document_formats = (
397+ self ._client .document_translation .get_supported_document_formats (** kwargs )
398+ )
399+ return FileFormat ._from_generated_list ( # pylint: disable=protected-access
400+ document_formats .value
401+ )
0 commit comments