|
| 1 | +# coding=utf-8 |
| 2 | +# ------------------------------------ |
| 3 | +# Copyright (c) Microsoft Corporation. |
| 4 | +# Licensed under the MIT License. |
| 5 | +# ------------------------------------ |
| 6 | + |
| 7 | +from typing import Union, Any, TYPE_CHECKING, List |
| 8 | +from azure.core.tracing.decorator import distributed_trace |
| 9 | +from ._generated import BatchDocumentTranslationClient as _BatchDocumentTranslationClient |
| 10 | +from ._helpers import get_authentication_policy |
| 11 | +from ._user_agent import USER_AGENT |
| 12 | +if TYPE_CHECKING: |
| 13 | + from azure.core.paging import ItemPaged |
| 14 | + from azure.core.credentials import AzureKeyCredential, TokenCredential |
| 15 | + from ._models import JobStatusDetail, DocumentStatusDetail, BatchDocumentInput, FileFormat |
| 16 | + |
| 17 | + |
| 18 | +class DocumentTranslationClient(object): |
| 19 | + """DocumentTranslationClient |
| 20 | +
|
| 21 | + """ |
| 22 | + |
| 23 | + def __init__(self, endpoint, credential, **kwargs): |
| 24 | + # type: (str, Union[AzureKeyCredential, TokenCredential], **Any) -> None |
| 25 | + """ |
| 26 | +
|
| 27 | + :param str endpoint: |
| 28 | + :param credential: |
| 29 | + :type credential: Union[AzureKeyCredential, TokenCredential] |
| 30 | + :keyword str api_version: |
| 31 | + """ |
| 32 | + self._endpoint = endpoint |
| 33 | + self._credential = credential |
| 34 | + self._api_version = kwargs.pop('api_version', None) |
| 35 | + |
| 36 | + authentication_policy = get_authentication_policy(credential) |
| 37 | + self._client = _BatchDocumentTranslationClient( |
| 38 | + endpoint=endpoint, |
| 39 | + credential=credential, # type: ignore |
| 40 | + api_version=self._api_version, |
| 41 | + sdk_moniker=USER_AGENT, |
| 42 | + authentication_policy=authentication_policy, |
| 43 | + polling_interval=5, # TODO what is appropriate polling interval |
| 44 | + **kwargs |
| 45 | + ) |
| 46 | + |
| 47 | + @distributed_trace |
| 48 | + def create_translation_job(self, batch, **kwargs): |
| 49 | + # type: (List[BatchDocumentInput], **Any) -> JobStatusDetail |
| 50 | + """ |
| 51 | +
|
| 52 | + :param batch: |
| 53 | + :type batch: List[~azure.ai.documenttranslation.BatchDocumentInput] |
| 54 | + :return: JobStatusDetail |
| 55 | + :rtype: JobStatusDetail |
| 56 | + """ |
| 57 | + |
| 58 | + return self._client.document_translation.begin_submit_batch_request( |
| 59 | + inputs=batch, |
| 60 | + polling=True, |
| 61 | + **kwargs |
| 62 | + ) |
| 63 | + |
| 64 | + @distributed_trace |
| 65 | + def get_job_status(self, job_id, **kwargs): |
| 66 | + # type: (str, **Any) -> JobStatusDetail |
| 67 | + """ |
| 68 | +
|
| 69 | + :param job_id: guid id for job |
| 70 | + :type job_id: str |
| 71 | + :rtype: ~azure.ai.documenttranslation.JobStatusDetail |
| 72 | + """ |
| 73 | + |
| 74 | + return self._client.document_translation.get_operation_status(job_id, **kwargs) |
| 75 | + |
| 76 | + @distributed_trace |
| 77 | + def cancel_job(self, job_id, **kwargs): |
| 78 | + # type: (str, **Any) -> None |
| 79 | + """ |
| 80 | +
|
| 81 | + :param job_id: guid id for job |
| 82 | + :type job_id: str |
| 83 | + :rtype: None |
| 84 | + """ |
| 85 | + |
| 86 | + self._client.document_translation.cancel_operation(job_id, **kwargs) |
| 87 | + |
| 88 | + @distributed_trace |
| 89 | + def wait_until_done(self, job_id, **kwargs): |
| 90 | + # type: (str, **Any) -> JobStatusDetail |
| 91 | + """ |
| 92 | +
|
| 93 | + :param job_id: guid id for job |
| 94 | + :type job_id: str |
| 95 | + :return: JobStatusDetail |
| 96 | + :rtype: JobStatusDetail |
| 97 | + """ |
| 98 | + pass |
| 99 | + |
| 100 | + @distributed_trace |
| 101 | + def list_submitted_jobs(self, **kwargs): |
| 102 | + # type: (**Any) -> ItemPaged[JobStatusDetail] |
| 103 | + """ |
| 104 | +
|
| 105 | + :keyword int results_per_page: |
| 106 | + :keyword int skip: |
| 107 | + :rtype: ~azure.core.polling.ItemPaged[JobStatusDetail] |
| 108 | + """ |
| 109 | + return self._client.document_translation.get_operations(**kwargs) |
| 110 | + |
| 111 | + @distributed_trace |
| 112 | + def list_documents_statuses(self, job_id, **kwargs): |
| 113 | + # type: (str, **Any) -> ItemPaged[DocumentStatusDetail] |
| 114 | + """ |
| 115 | +
|
| 116 | + :param job_id: guid id for job |
| 117 | + :type job_id: str |
| 118 | + :keyword int results_per_page: |
| 119 | + :keyword int skip: |
| 120 | + :rtype: ~azure.core.paging.ItemPaged[DocumentStatusDetail] |
| 121 | + """ |
| 122 | + |
| 123 | + return self._client.document_translation.get_operation_documents_status(job_id, **kwargs) |
| 124 | + |
| 125 | + @distributed_trace |
| 126 | + def get_document_status(self, job_id, document_id, **kwargs): |
| 127 | + # type: (str, str, **Any) -> DocumentStatusDetail |
| 128 | + """ |
| 129 | +
|
| 130 | + :param job_id: guid id for job |
| 131 | + :type job_id: str |
| 132 | + :param document_id: guid id for document |
| 133 | + :type document_id: str |
| 134 | + :rtype: ~azure.ai.documenttranslation.DocumentStatusDetail |
| 135 | + """ |
| 136 | + return self._client.document_translation.get_document_status(job_id, document_id, **kwargs) |
| 137 | + |
| 138 | + @distributed_trace |
| 139 | + def get_supported_storage_sources(self, **kwargs): |
| 140 | + # type: (**Any) -> List[str] |
| 141 | + """ |
| 142 | +
|
| 143 | + :rtype: List[str] |
| 144 | + """ |
| 145 | + return self._client.document_translation.get_document_storage_source(**kwargs) |
| 146 | + |
| 147 | + @distributed_trace |
| 148 | + def get_supported_glossary_formats(self, **kwargs): |
| 149 | + # type: (**Any) -> List[FileFormat] |
| 150 | + """ |
| 151 | +
|
| 152 | + :rtype: List[FileFormat] |
| 153 | + """ |
| 154 | + |
| 155 | + return self._client.document_translation.get_glossary_formats(**kwargs) |
| 156 | + |
| 157 | + @distributed_trace |
| 158 | + def get_supported_document_formats(self, **kwargs): |
| 159 | + # type: (**Any) -> List[FileFormat] |
| 160 | + """ |
| 161 | +
|
| 162 | + :rtype: List[FileFormat] |
| 163 | + """ |
| 164 | + |
| 165 | + return self._client.document_translation.get_document_formats(**kwargs) |
0 commit comments