From a61216b5a95cecd5b7fb29163ece9a718186a920 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 7 Jun 2021 11:58:55 -0700 Subject: [PATCH 1/5] fix type hint --- .../azure/ai/translation/document/_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py index 1026ea8506dc..fd67a1e4161a 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py @@ -98,7 +98,7 @@ def close(self): @overload def begin_translation(self, source_url, target_url, target_language_code, **kwargs): - # type: (str, str, str, **Any) -> DocumentTranslationPoller[ItemPaged[DocumentStatusResult]] + # type: (str, str, str, **Any) -> DocumentTranslationLROPoller[ItemPaged[DocumentStatusResult]] pass @overload From 0e534d88f18705574b6b7a348cdca337d5fdc533 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 7 Jun 2021 12:13:43 -0700 Subject: [PATCH 2/5] run black formatting --- .../azure/ai/translation/document/__init__.py | 4 +- .../ai/translation/document/_api_version.py | 3 +- .../azure/ai/translation/document/_client.py | 86 +++-- .../azure/ai/translation/document/_helpers.py | 35 +- .../azure/ai/translation/document/_models.py | 310 ++++++++++-------- .../azure/ai/translation/document/_polling.py | 50 +-- .../ai/translation/document/aio/__init__.py | 5 +- .../document/aio/_async_polling.py | 48 ++- .../translation/document/aio/_client_async.py | 83 +++-- 9 files changed, 372 insertions(+), 252 deletions(-) diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/__init__.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/__init__.py index b3dfcbe117e2..d931ef8091eb 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/__init__.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/__init__.py @@ -18,7 +18,7 @@ DocumentTranslationError, TranslationGlossary, DocumentTranslationInput, - FileFormat + FileFormat, ) __VERSION__ = VERSION @@ -35,5 +35,5 @@ "TranslationStatusResult", "DocumentStatusResult", "DocumentTranslationError", - "DocumentTranslationLROPoller" + "DocumentTranslationLROPoller", ] diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_api_version.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_api_version.py index 93bf32334882..8de3ea5311bf 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_api_version.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_api_version.py @@ -24,5 +24,6 @@ def validate_api_version(api_version): except ValueError: raise ValueError( "Unsupported API version '{}'. Please select from:\n{}".format( - api_version, ", ".join(v.value for v in DocumentTranslationApiVersion)) + api_version, ", ".join(v.value for v in DocumentTranslationApiVersion) + ) ) diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py index fd67a1e4161a..678e0011f515 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py @@ -7,12 +7,14 @@ import json from typing import Any, TYPE_CHECKING, List, Union, overload from azure.core.tracing.decorator import distributed_trace -from ._generated import BatchDocumentTranslationClient as _BatchDocumentTranslationClient +from ._generated import ( + BatchDocumentTranslationClient as _BatchDocumentTranslationClient, +) from ._models import ( TranslationStatusResult, DocumentStatusResult, DocumentTranslationInput, - FileFormat + FileFormat, ) from ._user_agent import USER_AGENT from ._polling import TranslationPolling, DocumentTranslationLROPollingMethod @@ -21,8 +23,9 @@ convert_datetime, get_authentication_policy, get_translation_input, - POLLING_INTERVAL + POLLING_INTERVAL, ) + if TYPE_CHECKING: from azure.core.paging import ItemPaged from azure.core.credentials import TokenCredential, AzureKeyCredential @@ -30,7 +33,6 @@ class DocumentTranslationClient(object): # pylint: disable=r0205 - def __init__(self, endpoint, credential, **kwargs): # type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None """DocumentTranslationClient is your interface to the Document Translation service. @@ -67,7 +69,7 @@ def __init__(self, endpoint, credential, **kwargs): """ self._endpoint = endpoint self._credential = credential - self._api_version = kwargs.pop('api_version', None) + self._api_version = kwargs.pop("api_version", None) authentication_policy = get_authentication_policy(credential) polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL) @@ -106,7 +108,9 @@ def begin_translation(self, inputs, **kwargs): # type: (List[DocumentTranslationInput], **Any) -> DocumentTranslationLROPoller[ItemPaged[DocumentStatusResult]] pass - def begin_translation(self, *args, **kwargs): # pylint: disable=client-method-missing-type-annotations + def begin_translation( + self, *args, **kwargs + ): # pylint: disable=client-method-missing-type-annotations """Begin translating the document(s) in your source container to your target container in the given language. To perform a single translation from source to target, pass the `source_url`, `target_url`, and `target_language_code` parameters. To pass multiple inputs for translation, including @@ -153,7 +157,8 @@ def deserialization_callback( return self.list_all_document_statuses(translation_status["id"]) polling_interval = kwargs.pop( - "polling_interval", self._client._config.polling_interval # pylint: disable=protected-access + "polling_interval", + self._client._config.polling_interval, # pylint: disable=protected-access ) pipeline_response = None @@ -168,11 +173,10 @@ def deserialization_callback( inputs=inputs if not continuation_token else None, polling=DocumentTranslationLROPollingMethod( timeout=polling_interval, - lro_algorithms=[ - TranslationPolling() - ], + lro_algorithms=[TranslationPolling()], cont_token_response=pipeline_response, - **kwargs), + **kwargs + ), cls=callback, continuation_token=continuation_token, **kwargs @@ -192,8 +196,12 @@ def get_translation_status(self, translation_id, **kwargs): :raises ~azure.core.exceptions.HttpResponseError or ~azure.core.exceptions.ResourceNotFoundError: """ - translation_status = self._client.document_translation.get_translation_status(translation_id, **kwargs) - return TranslationStatusResult._from_generated(translation_status) # pylint: disable=protected-access + translation_status = self._client.document_translation.get_translation_status( + translation_id, **kwargs + ) + return TranslationStatusResult._from_generated( # pylint: disable=protected-access + translation_status + ) @distributed_trace def cancel_translation(self, translation_id, **kwargs): @@ -248,14 +256,19 @@ def list_all_translation_statuses(self, **kwargs): results_per_page = kwargs.pop("results_per_page", None) translation_ids = kwargs.pop("translation_ids", None) - def _convert_from_generated_model(generated_model): # pylint: disable=protected-access - return TranslationStatusResult._from_generated(generated_model) # pylint: disable=protected-access + def _convert_from_generated_model( + generated_model, + ): # pylint: disable=protected-access + return TranslationStatusResult._from_generated( + generated_model + ) # pylint: disable=protected-access model_conversion_function = kwargs.pop( "cls", lambda translation_statuses: [ _convert_from_generated_model(status) for status in translation_statuses - ]) + ], + ) return self._client.document_translation.get_translations_status( cls=model_conversion_function, @@ -298,20 +311,26 @@ def list_all_document_statuses(self, translation_id, **kwargs): """ translated_after = kwargs.pop("translated_after", None) translated_before = kwargs.pop("translated_before", None) - translated_after = convert_datetime(translated_after) if translated_after else None - translated_before = convert_datetime(translated_before) if translated_before else None + translated_after = ( + convert_datetime(translated_after) if translated_after else None + ) + translated_before = ( + convert_datetime(translated_before) if translated_before else None + ) results_per_page = kwargs.pop("results_per_page", None) document_ids = kwargs.pop("document_ids", None) - def _convert_from_generated_model(generated_model): - return DocumentStatusResult._from_generated(generated_model) # pylint: disable=protected-access + return DocumentStatusResult._from_generated( # pylint: disable=protected-access + generated_model + ) model_conversion_function = kwargs.pop( "cls", lambda doc_statuses: [ _convert_from_generated_model(doc_status) for doc_status in doc_statuses - ]) + ], + ) return self._client.document_translation.get_documents_status( id=translation_id, @@ -336,10 +355,11 @@ def get_document_status(self, translation_id, document_id, **kwargs): """ document_status = self._client.document_translation.get_document_status( - translation_id, - document_id, - **kwargs) - return DocumentStatusResult._from_generated(document_status) # pylint: disable=protected-access + translation_id, document_id, **kwargs + ) + return DocumentStatusResult._from_generated( # pylint: disable=protected-access + document_status + ) @distributed_trace def get_glossary_formats(self, **kwargs): @@ -351,8 +371,12 @@ def get_glossary_formats(self, **kwargs): :raises ~azure.core.exceptions.HttpResponseError: """ - glossary_formats = self._client.document_translation.get_supported_glossary_formats(**kwargs) - return FileFormat._from_generated_list(glossary_formats.value) # pylint: disable=protected-access + glossary_formats = ( + self._client.document_translation.get_supported_glossary_formats(**kwargs) + ) + return FileFormat._from_generated_list( # pylint: disable=protected-access + glossary_formats.value + ) @distributed_trace def get_document_formats(self, **kwargs): @@ -364,5 +388,9 @@ def get_document_formats(self, **kwargs): :raises ~azure.core.exceptions.HttpResponseError: """ - document_formats = self._client.document_translation.get_supported_document_formats(**kwargs) - return FileFormat._from_generated_list(document_formats.value) # pylint: disable=protected-access + document_formats = ( + self._client.document_translation.get_supported_document_formats(**kwargs) + ) + return FileFormat._from_generated_list( # pylint: disable=protected-access + document_formats.value + ) diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py index 4299cffd492c..745be9d92ac9 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py @@ -16,20 +16,24 @@ TargetInput as _TargetInput, ) from ._models import DocumentTranslationInput + COGNITIVE_KEY_HEADER = "Ocp-Apim-Subscription-Key" POLLING_INTERVAL = 1 def get_translation_input(args, kwargs, continuation_token): try: - inputs = kwargs.pop('inputs', None) + inputs = kwargs.pop("inputs", None) if not inputs: inputs = args[0] - request = DocumentTranslationInput._to_generated_list(inputs) \ - if not continuation_token else None # pylint: disable=protected-access + request = ( + DocumentTranslationInput._to_generated_list(inputs) # pylint: disable=protected-access + if not continuation_token + else None + ) except (AttributeError, TypeError, IndexError): try: - source_url = kwargs.pop('source_url', None) + source_url = kwargs.pop("source_url", None) if not source_url: source_url = args[0] target_url = kwargs.pop("target_url", None) @@ -40,18 +44,19 @@ def get_translation_input(args, kwargs, continuation_token): target_language_code = args[2] request = [ _BatchRequest( - source=_SourceInput( - source_url=source_url - ), - targets=[_TargetInput( - target_url=target_url, - language=target_language_code - )] + source=_SourceInput(source_url=source_url), + targets=[ + _TargetInput( + target_url=target_url, language=target_language_code + ) + ], ) ] except (AttributeError, TypeError, IndexError): - raise ValueError("Pass 'inputs' for multiple inputs or 'source_url', 'target_url', " - "and 'target_language_code' for a single input.") + raise ValueError( + "Pass 'inputs' for multiple inputs or 'source_url', 'target_url', " + "and 'target_language_code' for a single input." + ) return request @@ -85,7 +90,7 @@ def get_http_logging_policy(**kwargs): "Set-Cookie", "X-Powered-By", "Strict-Transport-Security", - "x-content-type-options" + "x-content-type-options", } ) http_logging_policy.allowed_query_params.update( @@ -97,7 +102,7 @@ def get_http_logging_policy(**kwargs): "statuses", "createdDateTimeUtcStart", "createdDateTimeUtcEnd", - "$orderBy" + "$orderBy", } ) return http_logging_policy diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_models.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_models.py index a44a57626010..8124742d7d57 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_models.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_models.py @@ -11,7 +11,7 @@ SourceInput as _SourceInput, DocumentFilter as _DocumentFilter, TargetInput as _TargetInput, - Glossary as _Glossary + Glossary as _Glossary, ) @@ -41,12 +41,7 @@ class TranslationGlossary(object): # pylint: disable=useless-object-inheritance Currently only "AzureBlob" is supported. """ - def __init__( - self, - glossary_url, - file_format, - **kwargs - ): + def __init__(self, glossary_url, file_format, **kwargs): # type: (str, str, **Any) -> None self.glossary_url = glossary_url self.file_format = file_format @@ -55,21 +50,28 @@ def __init__( def _to_generated(self): return _Glossary( - glossary_url=self.glossary_url, - format=self.file_format, - version=self.format_version, - storage_source=self.storage_source - ) + glossary_url=self.glossary_url, + format=self.file_format, + version=self.format_version, + storage_source=self.storage_source, + ) @staticmethod def _to_generated_list(glossaries): - return [glossary._to_generated() for glossary in glossaries] # pylint: disable=protected-access + return [ + glossary._to_generated() for glossary in glossaries # pylint: disable=protected-access + ] def __repr__(self): - return "TranslationGlossary(glossary_url={}, " \ - "file_format={}, format_version={}, storage_source={})" \ - .format(self.glossary_url, self.file_format, - self.format_version, self.storage_source)[:1024] + return ( + "TranslationGlossary(glossary_url={}, " + "file_format={}, format_version={}, storage_source={})".format( + self.glossary_url, + self.file_format, + self.format_version, + self.storage_source, + )[:1024] + ) class TranslationTarget(object): # pylint: disable=useless-object-inheritance @@ -98,12 +100,7 @@ class TranslationTarget(object): # pylint: disable=useless-object-inheritance Currently only "AzureBlob" is supported. """ - def __init__( - self, - target_url, - language_code, - **kwargs - ): + def __init__(self, target_url, language_code, **kwargs): # type: (str, str, **Any) -> None self.target_url = target_url self.language_code = language_code @@ -117,20 +114,30 @@ def _to_generated(self): category=self.category_id, language=self.language_code, storage_source=self.storage_source, - glossaries=TranslationGlossary._to_generated_list(self.glossaries) # pylint: disable=protected-access - if self.glossaries else None + glossaries=TranslationGlossary._to_generated_list( # pylint: disable=protected-access + self.glossaries + ) + if self.glossaries + else None, ) @staticmethod def _to_generated_list(targets): - return [target._to_generated() for target in targets] # pylint: disable=protected-access - + return [ + target._to_generated() for target in targets # pylint: disable=protected-access + ] def __repr__(self): - return "TranslationTarget(target_url={}, language_code={}, "\ - "category_id={}, glossaries={}, storage_source={})" \ - .format(self.target_url, self.language_code, - self.category_id, self.glossaries.__repr__(), self.storage_source)[:1024] + return ( + "TranslationTarget(target_url={}, language_code={}, " + "category_id={}, glossaries={}, storage_source={})".format( + self.target_url, + self.language_code, + self.category_id, + self.glossaries.__repr__(), + self.storage_source, + )[:1024] + ) class DocumentTranslationInput(object): # pylint: disable=useless-object-inheritance @@ -177,12 +184,7 @@ class DocumentTranslationInput(object): # pylint: disable=useless-object-inheri Currently only "AzureBlob" is supported. """ - def __init__( - self, - source_url, - targets, - **kwargs - ): + def __init__(self, source_url, targets, **kwargs): # type: (str, List[TranslationTarget], **Any) -> None self.source_url = source_url self.targets = targets @@ -196,15 +198,14 @@ def _to_generated(self): return _BatchRequest( source=_SourceInput( source_url=self.source_url, - filter=_DocumentFilter( - prefix=self.prefix, - suffix=self.suffix - ), + filter=_DocumentFilter(prefix=self.prefix, suffix=self.suffix), language=self.source_language_code, - storage_source=self.storage_source + storage_source=self.storage_source, + ), + targets=TranslationTarget._to_generated_list( # pylint: disable=protected-access + self.targets ), - targets=TranslationTarget._to_generated_list(self.targets), # pylint: disable=protected-access - storage_type=self.storage_type + storage_type=self.storage_type, ) @staticmethod @@ -215,15 +216,24 @@ def _to_generated_list(batch_document_inputs): ] def __repr__(self): - return "DocumentTranslationInput(source_url={}, targets={}, "\ - "source_language_code={}, storage_type={}, "\ - "storage_source={}, prefix={}, suffix={})" \ - .format(self.source_url, self.targets.__repr__(), - self.source_language_code, self.storage_type.__repr__(), - self.storage_source, self.prefix, self.suffix)[:1024] + return ( + "DocumentTranslationInput(source_url={}, targets={}, " + "source_language_code={}, storage_type={}, " + "storage_source={}, prefix={}, suffix={})".format( + self.source_url, + self.targets.__repr__(), + self.source_language_code, + self.storage_type.__repr__(), + self.storage_source, + self.prefix, + self.suffix, + )[:1024] + ) -class TranslationStatusResult(object): # pylint: disable=useless-object-inheritance, too-many-instance-attributes +class TranslationStatusResult( + object +): # pylint: disable=useless-object-inheritance, too-many-instance-attributes """Status information about the translation operation. :ivar str id: Id of the translation operation. @@ -255,23 +265,24 @@ class TranslationStatusResult(object): # pylint: disable=useless-object-inherit :ivar int total_characters_charged: Total characters charged across all documents within the translation operation. """ - def __init__( - self, - **kwargs - ): + def __init__(self, **kwargs): # type: (**Any) -> None - self.id = kwargs.get('id') - self.created_on = kwargs.get('created_on') - self.last_updated_on = kwargs.get('last_updated_on', None) - self.status = kwargs.get('status', None) + self.id = kwargs.get("id") + self.created_on = kwargs.get("created_on") + self.last_updated_on = kwargs.get("last_updated_on", None) + self.status = kwargs.get("status", None) self.error = kwargs.get("error", None) - self.documents_total_count = kwargs.get('documents_total_count', None) - self.documents_failed_count = kwargs.get('documents_failed_count', None) - self.documents_succeeded_count = kwargs.get('documents_succeeded_count', None) - self.documents_in_progress_count = kwargs.get('documents_in_progress_count', None) - self.documents_not_yet_started_count = kwargs.get('documents_not_yet_started_count', None) - self.documents_cancelled_count = kwargs.get('documents_cancelled_count', None) - self.total_characters_charged = kwargs.get('total_characters_charged', None) + self.documents_total_count = kwargs.get("documents_total_count", None) + self.documents_failed_count = kwargs.get("documents_failed_count", None) + self.documents_succeeded_count = kwargs.get("documents_succeeded_count", None) + self.documents_in_progress_count = kwargs.get( + "documents_in_progress_count", None + ) + self.documents_not_yet_started_count = kwargs.get( + "documents_not_yet_started_count", None + ) + self.documents_cancelled_count = kwargs.get("documents_cancelled_count", None) + self.total_characters_charged = kwargs.get("total_characters_charged", None) @classmethod def _from_generated(cls, batch_status_details): @@ -282,31 +293,46 @@ def _from_generated(cls, batch_status_details): created_on=batch_status_details.created_date_time_utc, last_updated_on=batch_status_details.last_action_date_time_utc, status=batch_status_details.status, - error=DocumentTranslationError._from_generated(batch_status_details.error) # pylint: disable=protected-access - if batch_status_details.error else None, + error=DocumentTranslationError._from_generated( # pylint: disable=protected-access + batch_status_details.error + ) + if batch_status_details.error + else None, documents_total_count=batch_status_details.summary.total, documents_failed_count=batch_status_details.summary.failed, documents_succeeded_count=batch_status_details.summary.success, documents_in_progress_count=batch_status_details.summary.in_progress, documents_not_yet_started_count=batch_status_details.summary.not_yet_started, documents_cancelled_count=batch_status_details.summary.cancelled, - total_characters_charged=batch_status_details.summary.total_character_charged + total_characters_charged=batch_status_details.summary.total_character_charged, ) def __repr__(self): - return "TranslationStatusResult(id={}, created_on={}, "\ - "last_updated_on={}, status={}, error={}, documents_total_count={}, "\ - "documents_failed_count={}, documents_succeeded_count={}, "\ - "documents_in_progress_count={}, documents_not_yet_started_count={}, "\ - "documents_cancelled_count={}, total_characters_charged={})" \ - .format(self.id, self.created_on, self.last_updated_on, self.status, - self.error.__repr__(), self.documents_total_count, self.documents_failed_count, - self.documents_succeeded_count, self.documents_in_progress_count, - self.documents_not_yet_started_count, self.documents_cancelled_count, - self.total_characters_charged)[:1024] - - -class DocumentStatusResult(object): # pylint: disable=useless-object-inheritance, R0903, R0902 + return ( + "TranslationStatusResult(id={}, created_on={}, " + "last_updated_on={}, status={}, error={}, documents_total_count={}, " + "documents_failed_count={}, documents_succeeded_count={}, " + "documents_in_progress_count={}, documents_not_yet_started_count={}, " + "documents_cancelled_count={}, total_characters_charged={})".format( + self.id, + self.created_on, + self.last_updated_on, + self.status, + self.error.__repr__(), + self.documents_total_count, + self.documents_failed_count, + self.documents_succeeded_count, + self.documents_in_progress_count, + self.documents_not_yet_started_count, + self.documents_cancelled_count, + self.total_characters_charged, + )[:1024] + ) + + +class DocumentStatusResult( + object +): # pylint: disable=useless-object-inheritance, R0903, R0902 """Status information about a particular document within a translation operation. :ivar str source_document_url: Location of the source document in the source @@ -336,21 +362,18 @@ class DocumentStatusResult(object): # pylint: disable=useless-object-inheritanc :ivar int characters_charged: Characters charged for the document. """ - def __init__( - self, - **kwargs - ): + def __init__(self, **kwargs): # type: (**Any) -> None - self.source_document_url = kwargs.get('source_document_url', None) - self.translated_document_url = kwargs.get('translated_document_url', None) - self.created_on = kwargs['created_on'] - self.last_updated_on = kwargs['last_updated_on'] - self.status = kwargs['status'] - self.translated_to = kwargs['translated_to'] - self.error = kwargs.get('error', None) - self.translation_progress = kwargs.get('translation_progress', None) - self.id = kwargs.get('id', None) - self.characters_charged = kwargs.get('characters_charged', None) + self.source_document_url = kwargs.get("source_document_url", None) + self.translated_document_url = kwargs.get("translated_document_url", None) + self.created_on = kwargs["created_on"] + self.last_updated_on = kwargs["last_updated_on"] + self.status = kwargs["status"] + self.translated_to = kwargs["translated_to"] + self.error = kwargs.get("error", None) + self.translation_progress = kwargs.get("translation_progress", None) + self.id = kwargs.get("id", None) + self.characters_charged = kwargs.get("characters_charged", None) @classmethod def _from_generated(cls, doc_status): @@ -361,24 +384,38 @@ def _from_generated(cls, doc_status): last_updated_on=doc_status.last_action_date_time_utc, status=doc_status.status, translated_to=doc_status.to, - error=DocumentTranslationError._from_generated(doc_status.error) if doc_status.error else None, # pylint: disable=protected-access + error=DocumentTranslationError._from_generated(doc_status.error) # pylint: disable=protected-access + if doc_status.error + else None, translation_progress=doc_status.progress, id=doc_status.id, - characters_charged=doc_status.character_charged + characters_charged=doc_status.character_charged, ) def __repr__(self): # pylint: disable=line-too-long - return "DocumentStatusResult(id={}, source_document_url={}, "\ - "translated_document_url={}, created_on={}, last_updated_on={}, "\ - "status={}, translated_to={}, error={}, translation_progress={}, "\ - "characters_charged={})" \ - .format(self.id, self.source_document_url, self.translated_document_url, - self.created_on, self.last_updated_on, self.status, self.translated_to, - self.error.__repr__(), self.translation_progress, self.characters_charged)[:1024] + return ( + "DocumentStatusResult(id={}, source_document_url={}, " + "translated_document_url={}, created_on={}, last_updated_on={}, " + "status={}, translated_to={}, error={}, translation_progress={}, " + "characters_charged={})".format( + self.id, + self.source_document_url, + self.translated_document_url, + self.created_on, + self.last_updated_on, + self.status, + self.translated_to, + self.error.__repr__(), + self.translation_progress, + self.characters_charged, + )[:1024] + ) -class DocumentTranslationError(object): # pylint: disable=useless-object-inheritance, R0903 +class DocumentTranslationError( + object +): # pylint: disable=useless-object-inheritance, R0903 """This contains the error code, message, and target with descriptive details on why a translation operation or particular document failed. @@ -390,14 +427,11 @@ class DocumentTranslationError(object): # pylint: disable=useless-object-inheri For example it would be "documents" or "document id" in case of invalid document. """ - def __init__( - self, - **kwargs - ): + def __init__(self, **kwargs): # type: (**Any) -> None - self.code = kwargs.get('code', None) - self.message = kwargs.get('message', None) - self.target = kwargs.get('target', None) + self.code = kwargs.get("code", None) + self.message = kwargs.get("message", None) + self.target = kwargs.get("target", None) @classmethod def _from_generated(cls, error): @@ -406,17 +440,16 @@ def _from_generated(cls, error): return cls( code=inner_error.code, message=inner_error.message, - target=inner_error.target if inner_error.target is not None else error.target + target=inner_error.target + if inner_error.target is not None + else error.target, ) - return cls( - code=error.code, - message=error.message, - target=error.target - ) + return cls(code=error.code, message=error.message, target=error.target) def __repr__(self): - return "DocumentTranslationError(code={}, message={}, target={}" \ - .format(self.code, self.message, self.target)[:1024] + return "DocumentTranslationError(code={}, message={}, target={}".format( + self.code, self.message, self.target + )[:1024] class FileFormat(object): # pylint: disable=useless-object-inheritance, R0903 @@ -434,16 +467,13 @@ class FileFormat(object): # pylint: disable=useless-object-inheritance, R0903 :vartype default_format_version: str """ - def __init__( - self, - **kwargs - ): + def __init__(self, **kwargs): # type: (**Any) -> None - self.file_format = kwargs.get('file_format', None) - self.file_extensions = kwargs.get('file_extensions', None) - self.content_types = kwargs.get('content_types', None) - self.format_versions = kwargs.get('format_versions', None) - self.default_format_version = kwargs.get('default_format_version', None) + self.file_format = kwargs.get("file_format", None) + self.file_extensions = kwargs.get("file_extensions", None) + self.content_types = kwargs.get("content_types", None) + self.format_versions = kwargs.get("format_versions", None) + self.default_format_version = kwargs.get("default_format_version", None) @classmethod def _from_generated(cls, file_format): @@ -452,16 +482,24 @@ def _from_generated(cls, file_format): file_extensions=file_format.file_extensions, content_types=file_format.content_types, format_versions=file_format.versions, - default_format_version=file_format.default_version + default_format_version=file_format.default_version, ) @staticmethod def _from_generated_list(file_formats): - return [FileFormat._from_generated(file_formats) for file_formats in file_formats] + return [ + FileFormat._from_generated(file_formats) for file_formats in file_formats + ] def __repr__(self): # pylint: disable=line-too-long - return "FileFormat(file_format={}, file_extensions={}, "\ - "content_types={}, format_versions={}, default_format_version={}" \ - .format(self.file_format, self.file_extensions, self.content_types, - self.format_versions, self.default_format_version)[:1024] + return ( + "FileFormat(file_format={}, file_extensions={}, " + "content_types={}, format_versions={}, default_format_version={}".format( + self.file_format, + self.file_extensions, + self.content_types, + self.format_versions, + self.default_format_version, + )[:1024] + ) diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_polling.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_polling.py index 77d42cd8b7f0..698aab5896d5 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_polling.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_polling.py @@ -13,7 +13,7 @@ _as_json, BadResponse, OperationFailed, - _raise_if_bad_http_status_and_method + _raise_if_bad_http_status_and_method, ) from azure.core.exceptions import HttpResponseError, ODataV4Format @@ -38,8 +38,7 @@ class DocumentTranslationLROPoller(LROPoller): - """A custom poller implementation for Document Translation. - """ + """A custom poller implementation for Document Translation.""" @property def id(self): @@ -49,8 +48,12 @@ def id(self): :return: str """ if self._polling_method._current_body: # pylint: disable=protected-access - return self._polling_method._current_body.id # pylint: disable=protected-access - return self._polling_method._get_id_from_headers() # pylint: disable=protected-access + return ( + self._polling_method._current_body.id # pylint: disable=protected-access + ) + return ( + self._polling_method._get_id_from_headers() # pylint: disable=protected-access + ) @property def details(self): @@ -59,22 +62,25 @@ def details(self): :return: ~azure.ai.translation.document.TranslationStatusResult """ - return TranslationStatusResult._from_generated(self._polling_method._current_body) # pylint: disable=protected-access + return TranslationStatusResult._from_generated( # pylint: disable=protected-access + self._polling_method._current_body # pylint: disable=protected-access + ) @classmethod def from_continuation_token(cls, polling_method, continuation_token, **kwargs): # type: (DocumentTranslationLROPollingMethod, str, **Any) -> DocumentTranslationLROPoller - client, initial_response, deserialization_callback = polling_method.from_continuation_token( - continuation_token, **kwargs - ) + ( + client, + initial_response, + deserialization_callback, + ) = polling_method.from_continuation_token(continuation_token, **kwargs) return cls(client, initial_response, deserialization_callback, polling_method) class DocumentTranslationLROPollingMethod(LROBasePolling): - """A custom polling method implementation for Document Translation. - """ + """A custom polling method implementation for Document Translation.""" def __init__(self, *args, **kwargs): self._cont_token_response = kwargs.pop("cont_token_response") @@ -87,7 +93,9 @@ def _current_body(self): def _get_id_from_headers(self): # type: () -> str - return self._pipeline_response.http_response.headers["Operation-Location"].split("/batches/")[1] + return self._pipeline_response.http_response.headers[ + "Operation-Location" + ].split("/batches/")[1] def finished(self): """Is this polling finished? @@ -118,12 +126,16 @@ def from_continuation_token(self, continuation_token, **kwargs): try: client = kwargs["client"] except KeyError: - raise ValueError("Need kwarg 'client' to be recreated from continuation_token") + raise ValueError( + "Need kwarg 'client' to be recreated from continuation_token" + ) try: deserialization_callback = kwargs["deserialization_callback"] except KeyError: - raise ValueError("Need kwarg 'deserialization_callback' to be recreated from continuation_token") + raise ValueError( + "Need kwarg 'deserialization_callback' to be recreated from continuation_token" + ) return client, self._cont_token_response, deserialization_callback @@ -152,13 +164,11 @@ def _poll(self): class TranslationPolling(OperationResourcePolling): - """Implements a Location polling. - """ + """Implements a Location polling.""" def can_poll(self, pipeline_response): # type: (PipelineResponseType) -> bool - """Answer if this polling method could be used. - """ + """Answer if this polling method could be used.""" response = pipeline_response.http_response can_poll = self._operation_location_header in response.headers if can_poll: @@ -191,7 +201,9 @@ def get_status(self, pipeline_response): if status: return self._map_nonstandard_statuses(status, body) raise BadResponse("No status found in body") - raise BadResponse("The response from long running operation does not contain a body.") + raise BadResponse( + "The response from long running operation does not contain a body." + ) # pylint: disable=R0201 def _map_nonstandard_statuses(self, status, body): diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/__init__.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/__init__.py index 628220378b13..0987d26b82c3 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/__init__.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/__init__.py @@ -7,7 +7,4 @@ from ._client_async import DocumentTranslationClient from ._async_polling import AsyncDocumentTranslationLROPoller -__all__ = [ - "DocumentTranslationClient", - "AsyncDocumentTranslationLROPoller" -] +__all__ = ["DocumentTranslationClient", "AsyncDocumentTranslationLROPoller"] diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_async_polling.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_async_polling.py index 4edadf36f3d0..a042e14a7339 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_async_polling.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_async_polling.py @@ -8,7 +8,7 @@ from azure.core.polling import AsyncLROPoller from azure.core.polling.base_polling import ( OperationFailed, - _raise_if_bad_http_status_and_method + _raise_if_bad_http_status_and_method, ) from azure.core.polling.async_base_polling import AsyncLROBasePolling from .._generated.models import TranslationStatus @@ -20,8 +20,7 @@ class AsyncDocumentTranslationLROPoller(AsyncLROPoller[PollingReturnType]): - """An async custom poller implementation for Document Translation. - """ + """An async custom poller implementation for Document Translation.""" @property def id(self) -> str: @@ -30,8 +29,12 @@ def id(self) -> str: :return: str """ if self._polling_method._current_body: # pylint: disable=protected-access - return self._polling_method._current_body.id # pylint: disable=protected-access - return self._polling_method._get_id_from_headers() # pylint: disable=protected-access + return ( + self._polling_method._current_body.id # pylint: disable=protected-access + ) + return ( + self._polling_method._get_id_from_headers() # pylint: disable=protected-access + ) @property def details(self) -> TranslationStatusResult: @@ -39,26 +42,29 @@ def details(self) -> TranslationStatusResult: :return: ~azure.ai.translation.document.TranslationStatusResult """ - return TranslationStatusResult._from_generated(self._polling_method._current_body) # pylint: disable=protected-access + return TranslationStatusResult._from_generated( # pylint: disable=protected-access + self._polling_method._current_body # pylint: disable=protected-access + ) @classmethod def from_continuation_token( - cls, - polling_method: "AsyncDocumentTranslationLROPollingMethod", - continuation_token: str, - **kwargs: Any + cls, + polling_method: "AsyncDocumentTranslationLROPollingMethod", + continuation_token: str, + **kwargs: Any ) -> "AsyncDocumentTranslationLROPoller": - client, initial_response, deserialization_callback = polling_method.from_continuation_token( - continuation_token, **kwargs - ) + ( + client, + initial_response, + deserialization_callback, + ) = polling_method.from_continuation_token(continuation_token, **kwargs) return cls(client, initial_response, deserialization_callback, polling_method) class AsyncDocumentTranslationLROPollingMethod(AsyncLROBasePolling): - """A custom polling method implementation for Document Translation. - """ + """A custom polling method implementation for Document Translation.""" def __init__(self, *args, **kwargs): self._cont_token_response = kwargs.pop("cont_token_response") @@ -69,7 +75,9 @@ def _current_body(self) -> TranslationStatus: return TranslationStatus.deserialize(self._pipeline_response) def _get_id_from_headers(self) -> str: - return self._pipeline_response.http_response.headers["Operation-Location"].split("/batches/")[1] + return self._pipeline_response.http_response.headers[ + "Operation-Location" + ].split("/batches/")[1] def finished(self): """Is this polling finished? @@ -98,12 +106,16 @@ def from_continuation_token(self, continuation_token: str, **kwargs: Any) -> Tup try: client = kwargs["client"] except KeyError: - raise ValueError("Need kwarg 'client' to be recreated from continuation_token") + raise ValueError( + "Need kwarg 'client' to be recreated from continuation_token" + ) try: deserialization_callback = kwargs["deserialization_callback"] except KeyError: - raise ValueError("Need kwarg 'deserialization_callback' to be recreated from continuation_token") + raise ValueError( + "Need kwarg 'deserialization_callback' to be recreated from continuation_token" + ) return client, self._cont_token_response, deserialization_callback diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py index 169e6b70b051..fce3034eb9bf 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py @@ -9,32 +9,40 @@ from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.tracing.decorator import distributed_trace from azure.core.async_paging import AsyncItemPaged -from .._generated.aio import BatchDocumentTranslationClient as _BatchDocumentTranslationClient +from .._generated.aio import ( + BatchDocumentTranslationClient as _BatchDocumentTranslationClient, +) from .._user_agent import USER_AGENT from .._models import ( TranslationStatusResult, DocumentTranslationInput, FileFormat, - DocumentStatusResult + DocumentStatusResult, ) from .._helpers import ( get_http_logging_policy, convert_datetime, get_authentication_policy, get_translation_input, - POLLING_INTERVAL + POLLING_INTERVAL, +) +from ._async_polling import ( + AsyncDocumentTranslationLROPollingMethod, + AsyncDocumentTranslationLROPoller, ) -from ._async_polling import AsyncDocumentTranslationLROPollingMethod, AsyncDocumentTranslationLROPoller from .._polling import TranslationPolling + if TYPE_CHECKING: from azure.core.credentials import AzureKeyCredential from azure.core.credentials_async import AsyncTokenCredential class DocumentTranslationClient(object): - def __init__( - self, endpoint: str, credential: Union["AzureKeyCredential", "AsyncTokenCredential"], **kwargs: Any + self, + endpoint: str, + credential: Union["AzureKeyCredential", "AsyncTokenCredential"], + **kwargs: Any ) -> None: """DocumentTranslationClient is your interface to the Document Translation service. Use the client to translate whole documents while preserving source document @@ -70,7 +78,7 @@ def __init__( """ self._endpoint = endpoint self._credential = credential - self._api_version = kwargs.pop('api_version', None) + self._api_version = kwargs.pop("api_version", None) authentication_policy = get_authentication_policy(credential) polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL) @@ -98,22 +106,20 @@ async def close(self) -> None: @overload async def begin_translation( - self, source_url: str, - target_url: str, - target_language_code: str, - **kwargs: Any + self, source_url: str, target_url: str, target_language_code: str, **kwargs: Any ) -> AsyncDocumentTranslationLROPoller[AsyncItemPaged[DocumentStatusResult]]: ... @overload async def begin_translation( - self, inputs: List[DocumentTranslationInput], - **kwargs: Any + self, inputs: List[DocumentTranslationInput], **kwargs: Any ) -> AsyncDocumentTranslationLROPoller[AsyncItemPaged[DocumentStatusResult]]: ... @distributed_trace_async - async def begin_translation(self, *args, **kwargs): # pylint: disable=client-method-missing-type-annotations + async def begin_translation( + self, *args, **kwargs + ): # pylint: disable=client-method-missing-type-annotations """Begin translating the document(s) in your source container to your target container in the given language. To perform a single translation from source to target, pass the `source_url`, `target_url`, and `target_language_code` parameters. To pass multiple inputs for translation, including @@ -160,7 +166,8 @@ def deserialization_callback( return self.list_all_document_statuses(translation_status["id"]) polling_interval = kwargs.pop( - "polling_interval", self._client._config.polling_interval # pylint: disable=protected-access + "polling_interval", + self._client._config.polling_interval, # pylint: disable=protected-access ) pipeline_response = None @@ -175,11 +182,10 @@ def deserialization_callback( inputs=inputs if not continuation_token else None, polling=AsyncDocumentTranslationLROPollingMethod( timeout=polling_interval, - lro_algorithms=[ - TranslationPolling() - ], + lro_algorithms=[TranslationPolling()], cont_token_response=pipeline_response, - **kwargs), + **kwargs + ), cls=callback, continuation_token=continuation_token, **kwargs @@ -199,7 +205,11 @@ async def get_translation_status(self, translation_id, **kwargs): :raises ~azure.core.exceptions.HttpResponseError or ~azure.core.exceptions.ResourceNotFoundError: """ - translation_status = await self._client.document_translation.get_translation_status(translation_id, **kwargs) + translation_status = ( + await self._client.document_translation.get_translation_status( + translation_id, **kwargs + ) + ) # pylint: disable=protected-access return TranslationStatusResult._from_generated(translation_status) @@ -218,7 +228,9 @@ async def cancel_translation(self, translation_id, **kwargs): :raises ~azure.core.exceptions.HttpResponseError or ~azure.core.exceptions.ResourceNotFoundError: """ - await self._client.document_translation.cancel_translation(translation_id, **kwargs) + await self._client.document_translation.cancel_translation( + translation_id, **kwargs + ) @distributed_trace def list_all_translation_statuses(self, **kwargs): @@ -263,7 +275,9 @@ def _convert_from_generated_model(generated_model): model_conversion_function = kwargs.pop( "cls", - lambda translation_statuses: [_convert_from_generated_model(status) for status in translation_statuses] + lambda translation_statuses: [ + _convert_from_generated_model(status) for status in translation_statuses + ], ) return self._client.document_translation.get_translations_status( @@ -307,8 +321,12 @@ def list_all_document_statuses(self, translation_id, **kwargs): """ translated_after = kwargs.pop("translated_after", None) translated_before = kwargs.pop("translated_before", None) - translated_after = convert_datetime(translated_after) if translated_after else None - translated_before = convert_datetime(translated_before) if translated_before else None + translated_after = ( + convert_datetime(translated_after) if translated_after else None + ) + translated_before = ( + convert_datetime(translated_before) if translated_before else None + ) results_per_page = kwargs.pop("results_per_page", None) document_ids = kwargs.pop("document_ids", None) @@ -318,7 +336,9 @@ def _convert_from_generated_model(generated_model): model_conversion_function = kwargs.pop( "cls", - lambda doc_statuses: [_convert_from_generated_model(doc_status) for doc_status in doc_statuses] + lambda doc_statuses: [ + _convert_from_generated_model(doc_status) for doc_status in doc_statuses + ], ) return self._client.document_translation.get_documents_status( @@ -348,7 +368,6 @@ async def get_document_status(self, translation_id, document_id, **kwargs): # pylint: disable=protected-access return DocumentStatusResult._from_generated(document_status) - @distributed_trace_async async def get_glossary_formats(self, **kwargs): # type: (**Any) -> List[FileFormat] @@ -358,7 +377,11 @@ async def get_glossary_formats(self, **kwargs): :rtype: List[FileFormat] :raises ~azure.core.exceptions.HttpResponseError: """ - glossary_formats = await self._client.document_translation.get_supported_glossary_formats(**kwargs) + glossary_formats = ( + await self._client.document_translation.get_supported_glossary_formats( + **kwargs + ) + ) # pylint: disable=protected-access return FileFormat._from_generated_list(glossary_formats.value) @@ -371,6 +394,10 @@ async def get_document_formats(self, **kwargs): :rtype: List[FileFormat] :raises ~azure.core.exceptions.HttpResponseError: """ - document_formats = await self._client.document_translation.get_supported_document_formats(**kwargs) + document_formats = ( + await self._client.document_translation.get_supported_document_formats( + **kwargs + ) + ) # pylint: disable=protected-access return FileFormat._from_generated_list(document_formats.value) From eaca5334ba7a0436bcde870e04313667a2456f48 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 7 Jun 2021 13:09:35 -0700 Subject: [PATCH 3/5] docs sweep --- .../azure-ai-translation-document/README.md | 12 ++++------ .../azure/ai/translation/document/_client.py | 23 +++++++++++-------- .../azure/ai/translation/document/_models.py | 2 -- .../azure/ai/translation/document/_polling.py | 7 +++--- .../document/aio/_async_polling.py | 7 +++--- .../translation/document/aio/_client_async.py | 23 +++++++++++-------- .../samples/README.md | 4 ++-- ...st_document_statuses_with_filters_async.py | 4 ++-- ...le_list_translations_with_filters_async.py | 2 +- ...ple_list_document_statuses_with_filters.py | 4 ++-- .../sample_list_translations_with_filters.py | 2 +- 11 files changed, 49 insertions(+), 41 deletions(-) diff --git a/sdk/translation/azure-ai-translation-document/README.md b/sdk/translation/azure-ai-translation-document/README.md index 4b43217f9eeb..5fcc444b4a68 100644 --- a/sdk/translation/azure-ai-translation-document/README.md +++ b/sdk/translation/azure-ai-translation-document/README.md @@ -137,11 +137,9 @@ The client provides operations for: ### Translation Input -To begin translating your documents, pass a list of `DocumentTranslationInput` into the `begin_translation` client method. -Constructing a `DocumentTranslationInput` requires that you pass the SAS URLs to your source and target containers (or files) -and the target language(s) for translation. +Input to the `begin_translation` client method can be provided in two different ways: -A single source container with documents can be translated to a different language: +1) A single source container with documents can be translated to a different language: ```python from azure.core.credentials import AzureKeyCredential @@ -151,7 +149,7 @@ document_translation_client = DocumentTranslationClient("", AzureKeyCr poller = document_translation_client.begin_translation("", "", "") ``` -Or multiple different sources can be provided each with their own targets. +2) Or multiple different sources can be provided each with their own targets. ```python from azure.core.credentials import AzureKeyCredential @@ -240,7 +238,7 @@ for document in result: if document.status == "Succeeded": print("Source document location: {}".format(document.source_document_url)) print("Translated document location: {}".format(document.translated_document_url)) - print("Translated to language: {}\n".format(document.translate_to)) + print("Translated to language: {}\n".format(document.translated_to)) else: print("Error Code: {}, Message: {}\n".format(document.error.code, document.error.message)) ``` @@ -308,7 +306,7 @@ document_translation_client = DocumentTranslationClient(endpoint, credential) operations = document_translation_client.list_all_translation_statuses() # type: ItemPaged[TranslationStatusResult] for operation in operations: - print("ID: {}".format(operation.id)) + print("\nID: {}".format(operation.id)) print("Status: {}".format(operation.status)) print("Created on: {}".format(operation.created_on)) print("Last updated on: {}".format(operation.last_updated_on)) diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py index 678e0011f515..fb764d690e1a 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py @@ -114,7 +114,8 @@ def begin_translation( """Begin translating the document(s) in your source container to your target container in the given language. To perform a single translation from source to target, pass the `source_url`, `target_url`, and `target_language_code` parameters. To pass multiple inputs for translation, including - other translation options, pass the `inputs` parameter as a list of DocumentTranslationInput. + other translation options, pass the `inputs` parameter as a list of + :class:`~azure.ai.translation.document.DocumentTranslationInput`. For supported languages and document formats, see the service documentation: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview @@ -231,13 +232,15 @@ def list_all_translation_statuses(self, **kwargs): :keyword int results_per_page: is the number of operations returned per page. :keyword list[str] translation_ids: translation operations ids to filter by. :keyword list[str] statuses: translation operation statuses to filter by. - :keyword Union[str, datetime.datetime] created_after: get operations created after certain datetime. - :keyword Union[str, datetime.datetime] created_before: get operations created before certain datetime. + :keyword created_after: get operations created after certain datetime. + :paramtype created_after: Union[str, datetime.datetime] + :keyword created_before: get operations created before certain datetime. + :paramtype created_before: Union[str, datetime.datetime] :keyword list[str] order_by: the sorting query for the operations returned. format: ["parm1 asc/desc", "parm2 asc/desc", ...] (ex: 'createdDateTimeUtc asc', 'createdDateTimeUtc desc'). - :return: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document.TranslationStatusResult`] - :rtype: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document.TranslationStatusResult`] + :return: A pageable of TranslationStatusResult. + :rtype: ~azure.core.paging.ItemPaged[TranslationStatusResult] :raises ~azure.core.exceptions.HttpResponseError: .. admonition:: Example: @@ -291,13 +294,15 @@ def list_all_document_statuses(self, translation_id, **kwargs): :keyword int results_per_page: is the number of documents returned per page. :keyword list[str] document_ids: document IDs to filter by. :keyword list[str] statuses: document statuses to filter by. - :keyword Union[str, datetime.datetime] translated_after: get document translated after certain datetime. - :keyword Union[str, datetime.datetime] translated_before: get document translated before certain datetime. + :keyword translated_after: get document translated after certain datetime. + :paramtype translated_after: Union[str, datetime.datetime] + :keyword translated_before: get document translated before certain datetime. + :paramtype translated_before: Union[str, datetime.datetime] :keyword list[str] order_by: the sorting query for the documents. format: ["parm1 asc/desc", "parm2 asc/desc", ...] (ex: 'createdDateTimeUtc asc', 'createdDateTimeUtc desc'). - :return: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document.DocumentStatusResult`] - :rtype: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document.DocumentStatusResult`] + :return: A pageable of DocumentStatusResult. + :rtype: ~azure.core.paging.ItemPaged[DocumentStatusResult] :raises ~azure.core.exceptions.HttpResponseError: .. admonition:: Example: diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_models.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_models.py index 8124742d7d57..b23d601630ab 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_models.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_models.py @@ -256,8 +256,6 @@ class TranslationStatusResult( :vartype error: ~azure.ai.translation.document.DocumentTranslationError :ivar int documents_total_count: Number of translations to be made on documents in the operation. :ivar int documents_failed_count: Number of documents that failed translation. - More details can be found by calling the :func:`~DocumentTranslationClient.list_all_document_statuses` - client method. :ivar int documents_succeeded_count: Number of successful translations on documents. :ivar int documents_in_progress_count: Number of translations on documents in progress. :ivar int documents_not_yet_started_count: Number of documents that have not yet started being translated. diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_polling.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_polling.py index 698aab5896d5..99f8d1e9bd79 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_polling.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_polling.py @@ -38,14 +38,15 @@ class DocumentTranslationLROPoller(LROPoller): - """A custom poller implementation for Document Translation.""" + """A custom poller implementation for Document Translation. Call `result()` on the poller to return + a pageable of :class:`~azure.ai.translation.document.DocumentStatusResult`.""" @property def id(self): # type: () -> str """The ID for the translation operation - :return: str + :rtype: str """ if self._polling_method._current_body: # pylint: disable=protected-access return ( @@ -60,7 +61,7 @@ def details(self): # type: () -> TranslationStatusResult """The details for the translation operation - :return: ~azure.ai.translation.document.TranslationStatusResult + :rtype: ~azure.ai.translation.document.TranslationStatusResult """ return TranslationStatusResult._from_generated( # pylint: disable=protected-access self._polling_method._current_body # pylint: disable=protected-access diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_async_polling.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_async_polling.py index a042e14a7339..900b4f5a5c2c 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_async_polling.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_async_polling.py @@ -20,13 +20,14 @@ class AsyncDocumentTranslationLROPoller(AsyncLROPoller[PollingReturnType]): - """An async custom poller implementation for Document Translation.""" + """An async custom poller implementation for Document Translation. Call `result()` on the poller to return + a pageable of :class:`~azure.ai.translation.document.DocumentStatusResult`.""" @property def id(self) -> str: """The ID for the translation operation - :return: str + :rtype: str """ if self._polling_method._current_body: # pylint: disable=protected-access return ( @@ -40,7 +41,7 @@ def id(self) -> str: def details(self) -> TranslationStatusResult: """The details for the translation operation - :return: ~azure.ai.translation.document.TranslationStatusResult + :rtype: ~azure.ai.translation.document.TranslationStatusResult """ return TranslationStatusResult._from_generated( # pylint: disable=protected-access self._polling_method._current_body # pylint: disable=protected-access diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py index fce3034eb9bf..0bcf479c60d6 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py @@ -123,7 +123,8 @@ async def begin_translation( """Begin translating the document(s) in your source container to your target container in the given language. To perform a single translation from source to target, pass the `source_url`, `target_url`, and `target_language_code` parameters. To pass multiple inputs for translation, including - other translation options, pass the `inputs` parameter as a list of DocumentTranslationInput. + other translation options, pass the `inputs` parameter as a list of + :class:`~azure.ai.translation.document.DocumentTranslationInput`. For supported languages and document formats, see the service documentation: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview @@ -243,13 +244,15 @@ def list_all_translation_statuses(self, **kwargs): :keyword int results_per_page: is the number of operations returned per page. :keyword list[str] translation_ids: translation operations ids to filter by. :keyword list[str] statuses: translation operation statuses to filter by. - :keyword Union[str, datetime.datetime] created_after: get operations created after certain datetime. - :keyword Union[str, datetime.datetime] created_before: get operations created before certain datetime. + :keyword created_after: get operations created after certain datetime. + :paramtype created_after: Union[str, datetime.datetime] + :keyword created_before: get operations created before certain datetime. + :paramtype created_before: Union[str, datetime.datetime] :keyword list[str] order_by: the sorting query for the operations returned. format: ["parm1 asc/desc", "parm2 asc/desc", ...] (ex: 'createdDateTimeUtc asc', 'createdDateTimeUtc desc'). - :return: ~azure.core.paging.AsyncItemPaged[:class:`~azure.ai.translation.document.TranslationStatusResult`] - :rtype: ~azure.core.paging.AsyncItemPaged[:class:`~azure.ai.translation.document.TranslationStatusResult`] + :return: A pageable of TranslationStatusResult. + :rtype: ~azure.core.paging.ItemPaged[TranslationStatusResult] :raises ~azure.core.exceptions.HttpResponseError: .. admonition:: Example: @@ -301,13 +304,15 @@ def list_all_document_statuses(self, translation_id, **kwargs): :keyword int results_per_page: is the number of documents returned per page. :keyword list[str] document_ids: document IDs to filter by. :keyword list[str] statuses: document statuses to filter by. - :keyword Union[str, datetime.datetime] translated_after: get document translated after certain datetime. - :keyword Union[str, datetime.datetime] translated_before: get document translated before certain datetime. + :keyword translated_after: get document translated after certain datetime. + :paramtype translated_after: Union[str, datetime.datetime] + :keyword translated_before: get document translated before certain datetime. + :paramtype translated_before: Union[str, datetime.datetime] :keyword list[str] order_by: the sorting query for the documents. format: ["parm1 asc/desc", "parm2 asc/desc", ...] (ex: 'createdDateTimeUtc asc', 'createdDateTimeUtc desc'). - :return: ~azure.core.paging.AsyncItemPaged[:class:`~azure.ai.translation.document.DocumentStatusResult`] - :rtype: ~azure.core.paging.AsyncItemPaged[:class:`~azure.ai.translation.document.DocumentStatusResult`] + :return: A pageable of DocumentStatusResult. + :rtype: ~azure.core.paging.ItemPaged[DocumentStatusResult] :raises ~azure.core.exceptions.HttpResponseError: .. admonition:: Example: diff --git a/sdk/translation/azure-ai-translation-document/samples/README.md b/sdk/translation/azure-ai-translation-document/samples/README.md index f4a48560e499..97bb2d47dc02 100644 --- a/sdk/translation/azure-ai-translation-document/samples/README.md +++ b/sdk/translation/azure-ai-translation-document/samples/README.md @@ -31,7 +31,7 @@ These sample programs show common scenarios for the Document Translation client' ## Prerequisites * Python 2.7, or 3.6 or later is required to use this package (3.6 or later if using asyncio) * You must have an [Azure subscription][azure_subscription] and an -[Azure Translation account][azure_document_translation_account] to run these samples. +[Azure Translator account][azure_document_translation_account] to run these samples. ## Setup @@ -40,7 +40,7 @@ These sample programs show common scenarios for the Document Translation client' ```bash pip install azure-ai-translation-document --pre ``` -For more information about how the versioning story of the SDK corresponds to the versioning story of the service's API, see [here][versioning_story_readme]. +For more information about how the versioning of the SDK corresponds to the versioning of the service's API, see [here][versioning_story_readme]. 2. Clone or download this sample repository 3. Open the sample folder in Visual Studio Code or your IDE of choice. diff --git a/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_document_statuses_with_filters_async.py b/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_document_statuses_with_filters_async.py index 377fa3c0fa63..260f25bf35e4 100644 --- a/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_document_statuses_with_filters_async.py +++ b/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_document_statuses_with_filters_async.py @@ -8,8 +8,8 @@ FILE: sample_list_document_statuses_with_filters_async.py DESCRIPTION: - This sample demonstrates how to list all the document in a translation operation for the resource - using different kind of filters/sorting/paging options + This sample demonstrates how to list all the documents in a translation operation for the resource + using different kind of filters/sorting/paging options. To set up your containers for translation and generate SAS tokens to your containers (or files) with the appropriate permissions, see the README. diff --git a/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_translations_with_filters_async.py b/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_translations_with_filters_async.py index 9a682cc0aa76..ee63663e0496 100644 --- a/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_translations_with_filters_async.py +++ b/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_translations_with_filters_async.py @@ -9,7 +9,7 @@ DESCRIPTION: This sample demonstrates how to list all the submitted translation operations for the resource - using different kind of filters/sorting/paging options + using different kind of filters/sorting/paging options. To set up your containers for translation and generate SAS tokens to your containers (or files) with the appropriate permissions, see the README. diff --git a/sdk/translation/azure-ai-translation-document/samples/sample_list_document_statuses_with_filters.py b/sdk/translation/azure-ai-translation-document/samples/sample_list_document_statuses_with_filters.py index d189d0aadca9..3204a9819c06 100644 --- a/sdk/translation/azure-ai-translation-document/samples/sample_list_document_statuses_with_filters.py +++ b/sdk/translation/azure-ai-translation-document/samples/sample_list_document_statuses_with_filters.py @@ -8,8 +8,8 @@ FILE: sample_list_document_statuses_with_filters.py DESCRIPTION: - This sample demonstrates how to list all the document in a translation operation for the resource - using different kind of filters/sorting/paging options + This sample demonstrates how to list all the documents in a translation operation for the resource + using different kind of filters/sorting/paging options. To set up your containers for translation and generate SAS tokens to your containers (or files) with the appropriate permissions, see the README. diff --git a/sdk/translation/azure-ai-translation-document/samples/sample_list_translations_with_filters.py b/sdk/translation/azure-ai-translation-document/samples/sample_list_translations_with_filters.py index 709d6f26565c..e5c564d0c866 100644 --- a/sdk/translation/azure-ai-translation-document/samples/sample_list_translations_with_filters.py +++ b/sdk/translation/azure-ai-translation-document/samples/sample_list_translations_with_filters.py @@ -9,7 +9,7 @@ DESCRIPTION: This sample demonstrates how to list all the submitted translation operations for the resource - using different kind of filters/sorting/paging options + using different kind of filters/sorting/paging options. To set up your containers for translation and generate SAS tokens to your containers (or files) with the appropriate permissions, see the README. From 470369b68389ebc1e0f7f7e08adf2e45b4a7c4db Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 7 Jun 2021 13:09:45 -0700 Subject: [PATCH 4/5] update changelog date --- sdk/translation/azure-ai-translation-document/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/translation/azure-ai-translation-document/CHANGELOG.md b/sdk/translation/azure-ai-translation-document/CHANGELOG.md index d6fe420fe48d..441d63f97d95 100644 --- a/sdk/translation/azure-ai-translation-document/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-document/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.0.0b2 (Unreleased) +## 1.0.0b2 (2021-06-07) This version of the SDK defaults to the latest supported service version, which currently is v1.0 From b9590cdfdea49aefb0477241268475c59865da9f Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 7 Jun 2021 13:13:13 -0700 Subject: [PATCH 5/5] update date again --- sdk/translation/azure-ai-translation-document/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/translation/azure-ai-translation-document/CHANGELOG.md b/sdk/translation/azure-ai-translation-document/CHANGELOG.md index 441d63f97d95..0cd1adf133ba 100644 --- a/sdk/translation/azure-ai-translation-document/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-document/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.0.0b2 (2021-06-07) +## 1.0.0b2 (2021-06-08) This version of the SDK defaults to the latest supported service version, which currently is v1.0