|
| 1 | +# coding=utf-8 |
| 2 | +# -------------------------------------------------------------------------- |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | +# Code generated by Microsoft (R) Python Code Generator. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
| 7 | +# -------------------------------------------------------------------------- |
| 8 | + |
| 9 | +from copy import deepcopy |
| 10 | +from typing import Any |
| 11 | + |
| 12 | +from azure.core import PipelineClient |
| 13 | +from azure.core.rest import HttpRequest, HttpResponse |
| 14 | + |
| 15 | +from ._configuration import TextTranslationClientConfiguration |
| 16 | +from ._operations import TextTranslationClientOperationsMixin |
| 17 | +from ._serialization import Deserializer, Serializer |
| 18 | + |
| 19 | + |
| 20 | +class TextTranslationClient(TextTranslationClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword |
| 21 | + """Text translation is a cloud-based REST API feature of the Translator service that uses neural |
| 22 | + machine translation technology to enable quick and accurate source-to-target text translation |
| 23 | + in real time across all supported languages. |
| 24 | +
|
| 25 | + The following methods are supported by the Text Translation feature: |
| 26 | +
|
| 27 | + Languages. Returns a list of languages supported by Translate, Transliterate, and Dictionary |
| 28 | + Lookup operations. |
| 29 | +
|
| 30 | + Translate. Renders single source-language text to multiple target-language texts with a single |
| 31 | + request. |
| 32 | +
|
| 33 | + Transliterate. Converts characters or letters of a source language to the corresponding |
| 34 | + characters or letters of a target language. |
| 35 | +
|
| 36 | + Detect. Returns the source code language code and a boolean variable denoting whether the |
| 37 | + detected language is supported for text translation and transliteration. |
| 38 | +
|
| 39 | + Dictionary lookup. Returns equivalent words for the source term in the target language. |
| 40 | +
|
| 41 | + Dictionary example Returns grammatical structure and context examples for the source term and |
| 42 | + target term pair. |
| 43 | +
|
| 44 | + :param endpoint: Supported Text Translation endpoints (protocol and hostname, for example: |
| 45 | + https://api.cognitive.microsofttranslator.com). Required. |
| 46 | + :type endpoint: str |
| 47 | + :keyword api_version: Default value is "3.0". Note that overriding this default value may |
| 48 | + result in unsupported behavior. |
| 49 | + :paramtype api_version: str |
| 50 | + """ |
| 51 | + |
| 52 | + def __init__( # pylint: disable=missing-client-constructor-parameter-credential |
| 53 | + self, endpoint: str, **kwargs: Any |
| 54 | + ) -> None: |
| 55 | + _endpoint = "{Endpoint}" |
| 56 | + self._config = TextTranslationClientConfiguration(endpoint=endpoint, **kwargs) |
| 57 | + self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **kwargs) |
| 58 | + |
| 59 | + self._serialize = Serializer() |
| 60 | + self._deserialize = Deserializer() |
| 61 | + self._serialize.client_side_validation = False |
| 62 | + |
| 63 | + def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: |
| 64 | + """Runs the network request through the client's chained policies. |
| 65 | +
|
| 66 | + >>> from azure.core.rest import HttpRequest |
| 67 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 68 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 69 | + >>> response = client.send_request(request) |
| 70 | + <HttpResponse: 200 OK> |
| 71 | +
|
| 72 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 73 | +
|
| 74 | + :param request: The network request you want to make. Required. |
| 75 | + :type request: ~azure.core.rest.HttpRequest |
| 76 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
| 77 | + :return: The response of your network call. Does not do error handling on your response. |
| 78 | + :rtype: ~azure.core.rest.HttpResponse |
| 79 | + """ |
| 80 | + |
| 81 | + request_copy = deepcopy(request) |
| 82 | + path_format_arguments = { |
| 83 | + "Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), |
| 84 | + } |
| 85 | + |
| 86 | + request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) |
| 87 | + return self._client.send_request(request_copy, **kwargs) |
| 88 | + |
| 89 | + def close(self) -> None: |
| 90 | + self._client.close() |
| 91 | + |
| 92 | + def __enter__(self) -> "TextTranslationClient": |
| 93 | + self._client.__enter__() |
| 94 | + return self |
| 95 | + |
| 96 | + def __exit__(self, *exc_details: Any) -> None: |
| 97 | + self._client.__exit__(*exc_details) |
0 commit comments