|
1 | 1 | # coding=utf-8 |
2 | 2 | # -------------------------------------------------------------------------- |
3 | 3 | # Copyright (c) Microsoft Corporation. All rights reserved. |
4 | | -# Licensed under the MIT License. See License.txt in the project root for |
5 | | -# license information. |
6 | | -# |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
7 | 5 | # Code generated by Microsoft (R) AutoRest Code Generator. |
8 | | -# Changes may cause incorrect behavior and will be lost if the code is |
9 | | -# regenerated. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
10 | 7 | # -------------------------------------------------------------------------- |
11 | 8 |
|
12 | 9 | from typing import TYPE_CHECKING |
13 | 10 |
|
14 | 11 | from azure.core import PipelineClient |
15 | | -from azure.profiles import KnownProfiles, ProfileDefinition |
16 | | -from azure.profiles.multiapiclient import MultiApiClientMixin |
17 | 12 | from msrest import Deserializer, Serializer |
18 | 13 |
|
19 | | -from ._configuration import SearchClientConfiguration |
20 | | - |
21 | 14 | if TYPE_CHECKING: |
22 | 15 | # pylint: disable=unused-import,ungrouped-imports |
23 | | - from typing import Any, Optional |
| 16 | + from typing import Any |
24 | 17 |
|
25 | 18 | from azure.core.pipeline.transport import HttpRequest, HttpResponse |
26 | 19 |
|
27 | | -class _SDKClient(object): |
28 | | - def __init__(self, *args, **kwargs): |
29 | | - """This is a fake class to support current implemetation of MultiApiClientMixin." |
30 | | - Will be removed in final version of multiapi azure-core based client |
31 | | - """ |
32 | | - pass |
| 20 | +from ._configuration import SearchClientConfiguration |
| 21 | +from .operations import DocumentsOperations |
| 22 | +from . import models |
33 | 23 |
|
34 | | -class SearchClient(MultiApiClientMixin, _SDKClient): |
35 | | - """Client that can be used to query an index and upload, merge, or delete documents. |
36 | 24 |
|
37 | | - This ready contains multiple API versions, to help you deal with all of the Azure clouds |
38 | | - (Azure Stack, Azure Government, Azure China, etc.). |
39 | | - By default, it uses the latest API version available on public Azure. |
40 | | - For production, you should stick to a particular api-version and/or profile. |
41 | | - The profile sets a mapping between an operation group and its API version. |
42 | | - The api-version parameter sets the default API version if the operation |
43 | | - group is not described in the profile. |
| 25 | +class SearchClient(object): |
| 26 | + """Client that can be used to query an index and upload, merge, or delete documents. |
44 | 27 |
|
| 28 | + :ivar documents: DocumentsOperations operations |
| 29 | + :vartype documents: azure.search.documents.operations.DocumentsOperations |
45 | 30 | :param endpoint: The endpoint URL of the search service. |
46 | 31 | :type endpoint: str |
47 | 32 | :param index_name: The name of the index. |
48 | 33 | :type index_name: str |
49 | | - :param api_version: API version to use if no profile is provided, or if missing in profile. |
50 | | - :type api_version: str |
51 | | - :param profile: A profile definition, from KnownProfiles to dict. |
52 | | - :type profile: azure.profiles.KnownProfiles |
53 | 34 | """ |
54 | 35 |
|
55 | | - DEFAULT_API_VERSION = '2020-06-30-Preview' |
56 | | - _PROFILE_TAG = "azure.search.documents.SearchClient" |
57 | | - LATEST_PROFILE = ProfileDefinition({ |
58 | | - _PROFILE_TAG: { |
59 | | - None: DEFAULT_API_VERSION, |
60 | | - }}, |
61 | | - _PROFILE_TAG + " latest" |
62 | | - ) |
63 | | - |
64 | 36 | def __init__( |
65 | 37 | self, |
66 | 38 | endpoint, # type: str |
67 | 39 | index_name, # type: str |
68 | | - api_version=None, # type: Optional[str] |
69 | | - profile=KnownProfiles.default, # type: KnownProfiles |
70 | 40 | **kwargs # type: Any |
71 | 41 | ): |
72 | | - if api_version == '2020-06-30' or api_version == '2020-06-30-Preview': |
73 | | - base_url = '{endpoint}/indexes(\'{indexName}\')' |
74 | | - else: |
75 | | - raise ValueError("API version {} is not available".format(api_version)) |
| 42 | + # type: (...) -> None |
| 43 | + base_url = '{endpoint}/indexes(\'{indexName}\')' |
76 | 44 | self._config = SearchClientConfiguration(endpoint, index_name, **kwargs) |
77 | 45 | self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs) |
78 | | - super(SearchClient, self).__init__( |
79 | | - api_version=api_version, |
80 | | - profile=profile |
81 | | - ) |
82 | 46 |
|
83 | | - @classmethod |
84 | | - def _models_dict(cls, api_version): |
85 | | - return {k: v for k, v in cls.models(api_version).__dict__.items() if isinstance(v, type)} |
| 47 | + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} |
| 48 | + self._serialize = Serializer(client_models) |
| 49 | + self._serialize.client_side_validation = False |
| 50 | + self._deserialize = Deserializer(client_models) |
86 | 51 |
|
87 | | - @classmethod |
88 | | - def models(cls, api_version=DEFAULT_API_VERSION): |
89 | | - """Module depends on the API version: |
| 52 | + self.documents = DocumentsOperations( |
| 53 | + self._client, self._config, self._serialize, self._deserialize) |
90 | 54 |
|
91 | | - * 2020-06-30: :mod:`v2020_06.models<azure.search.documents.v2020_06.models>` |
92 | | - * 2020-06-30-Preview: :mod:`v2020_06_preview.models<azure.search.documents.v2020_06_preview.models>` |
93 | | - """ |
94 | | - if api_version == '2020-06-30': |
95 | | - from .v2020_06 import models |
96 | | - return models |
97 | | - elif api_version == '2020-06-30-Preview': |
98 | | - from .v2020_06_preview import models |
99 | | - return models |
100 | | - raise ValueError("API version {} is not available".format(api_version)) |
101 | | - |
102 | | - @property |
103 | | - def documents(self): |
104 | | - """Instance depends on the API version: |
105 | | -
|
106 | | - * 2020-06-30: :class:`DocumentsOperations<azure.search.documents.v2020_06.operations.DocumentsOperations>` |
107 | | - * 2020-06-30-Preview: :class:`DocumentsOperations<azure.search.documents.v2020_06_preview.operations.DocumentsOperations>` |
| 55 | + def _send_request(self, http_request, **kwargs): |
| 56 | + # type: (HttpRequest, Any) -> HttpResponse |
| 57 | + """Runs the network request through the client's chained policies. |
| 58 | +
|
| 59 | + :param http_request: The network request you want to make. Required. |
| 60 | + :type http_request: ~azure.core.pipeline.transport.HttpRequest |
| 61 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. |
| 62 | + :return: The response of your network call. Does not do error handling on your response. |
| 63 | + :rtype: ~azure.core.pipeline.transport.HttpResponse |
108 | 64 | """ |
109 | | - api_version = self._get_api_version('documents') |
110 | | - if api_version == '2020-06-30': |
111 | | - from .v2020_06.operations import DocumentsOperations as OperationClass |
112 | | - elif api_version == '2020-06-30-Preview': |
113 | | - from .v2020_06_preview.operations import DocumentsOperations as OperationClass |
114 | | - else: |
115 | | - raise ValueError("API version {} does not have operation group 'documents'".format(api_version)) |
116 | | - return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version))) |
| 65 | + path_format_arguments = { |
| 66 | + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), |
| 67 | + 'indexName': self._serialize.url("self._config.index_name", self._config.index_name, 'str'), |
| 68 | + } |
| 69 | + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) |
| 70 | + stream = kwargs.pop("stream", True) |
| 71 | + pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) |
| 72 | + return pipeline_response.http_response |
117 | 73 |
|
118 | 74 | def close(self): |
| 75 | + # type: () -> None |
119 | 76 | self._client.close() |
| 77 | + |
120 | 78 | def __enter__(self): |
| 79 | + # type: () -> SearchClient |
121 | 80 | self._client.__enter__() |
122 | 81 | return self |
| 82 | + |
123 | 83 | def __exit__(self, *exc_details): |
| 84 | + # type: (Any) -> None |
124 | 85 | self._client.__exit__(*exc_details) |
0 commit comments