azure-ai-textanalytics 5.3.0b1__py3-none-any.whl → 6.0.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of azure-ai-textanalytics might be problematic. Click here for more details.

Files changed (128) hide show
  1. azure/ai/textanalytics/__init__.py +26 -197
  2. azure/ai/textanalytics/_client.py +111 -0
  3. azure/ai/textanalytics/_configuration.py +73 -0
  4. azure/ai/textanalytics/{_generated/v2022_05_01/operations → _operations}/__init__.py +13 -8
  5. azure/ai/textanalytics/_operations/_operations.py +716 -0
  6. azure/ai/textanalytics/{_generated/v2022_05_01/models → _operations}/_patch.py +8 -6
  7. azure/ai/textanalytics/_patch.py +350 -0
  8. azure/ai/textanalytics/{_generated/aio → _utils}/__init__.py +1 -5
  9. azure/ai/textanalytics/_utils/model_base.py +1237 -0
  10. azure/ai/textanalytics/{_generated/_serialization.py → _utils/serialization.py} +640 -616
  11. azure/ai/textanalytics/{_generated/v2022_05_01/aio/_vendor.py → _utils/utils.py} +10 -12
  12. azure/ai/textanalytics/_version.py +8 -7
  13. azure/ai/textanalytics/aio/__init__.py +25 -14
  14. azure/ai/textanalytics/aio/_client.py +115 -0
  15. azure/ai/textanalytics/aio/_configuration.py +75 -0
  16. azure/ai/textanalytics/{_generated/v2022_10_01_preview/aio/operations → aio/_operations}/__init__.py +13 -8
  17. azure/ai/textanalytics/aio/_operations/_operations.py +623 -0
  18. azure/ai/textanalytics/{_generated/v2022_05_01 → aio/_operations}/_patch.py +8 -6
  19. azure/ai/textanalytics/aio/_patch.py +344 -0
  20. azure/ai/textanalytics/models/__init__.py +402 -0
  21. azure/ai/textanalytics/models/_enums.py +1979 -0
  22. azure/ai/textanalytics/models/_models.py +6641 -0
  23. azure/ai/textanalytics/{_generated/v2022_05_01/aio → models}/_patch.py +8 -6
  24. azure/ai/textanalytics/py.typed +1 -0
  25. {azure_ai_textanalytics-5.3.0b1.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/METADATA +755 -319
  26. azure_ai_textanalytics-6.0.0b1.dist-info/RECORD +29 -0
  27. {azure_ai_textanalytics-5.3.0b1.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/WHEEL +1 -1
  28. azure/ai/textanalytics/_base_client.py +0 -111
  29. azure/ai/textanalytics/_check.py +0 -22
  30. azure/ai/textanalytics/_dict_mixin.py +0 -54
  31. azure/ai/textanalytics/_generated/__init__.py +0 -16
  32. azure/ai/textanalytics/_generated/_configuration.py +0 -70
  33. azure/ai/textanalytics/_generated/_operations_mixin.py +0 -795
  34. azure/ai/textanalytics/_generated/_text_analytics_client.py +0 -126
  35. azure/ai/textanalytics/_generated/_version.py +0 -8
  36. azure/ai/textanalytics/_generated/aio/_configuration.py +0 -66
  37. azure/ai/textanalytics/_generated/aio/_operations_mixin.py +0 -776
  38. azure/ai/textanalytics/_generated/aio/_text_analytics_client.py +0 -124
  39. azure/ai/textanalytics/_generated/models.py +0 -8
  40. azure/ai/textanalytics/_generated/v2022_05_01/__init__.py +0 -20
  41. azure/ai/textanalytics/_generated/v2022_05_01/_configuration.py +0 -72
  42. azure/ai/textanalytics/_generated/v2022_05_01/_text_analytics_client.py +0 -100
  43. azure/ai/textanalytics/_generated/v2022_05_01/_vendor.py +0 -45
  44. azure/ai/textanalytics/_generated/v2022_05_01/aio/__init__.py +0 -20
  45. azure/ai/textanalytics/_generated/v2022_05_01/aio/_configuration.py +0 -71
  46. azure/ai/textanalytics/_generated/v2022_05_01/aio/_text_analytics_client.py +0 -97
  47. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/__init__.py +0 -18
  48. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/_patch.py +0 -121
  49. azure/ai/textanalytics/_generated/v2022_05_01/aio/operations/_text_analytics_client_operations.py +0 -603
  50. azure/ai/textanalytics/_generated/v2022_05_01/models/__init__.py +0 -281
  51. azure/ai/textanalytics/_generated/v2022_05_01/models/_models_py3.py +0 -5722
  52. azure/ai/textanalytics/_generated/v2022_05_01/models/_text_analytics_client_enums.py +0 -439
  53. azure/ai/textanalytics/_generated/v2022_05_01/operations/_patch.py +0 -120
  54. azure/ai/textanalytics/_generated/v2022_05_01/operations/_text_analytics_client_operations.py +0 -744
  55. azure/ai/textanalytics/_generated/v2022_10_01_preview/__init__.py +0 -20
  56. azure/ai/textanalytics/_generated/v2022_10_01_preview/_configuration.py +0 -72
  57. azure/ai/textanalytics/_generated/v2022_10_01_preview/_patch.py +0 -19
  58. azure/ai/textanalytics/_generated/v2022_10_01_preview/_text_analytics_client.py +0 -100
  59. azure/ai/textanalytics/_generated/v2022_10_01_preview/_vendor.py +0 -45
  60. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/__init__.py +0 -20
  61. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_configuration.py +0 -71
  62. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_patch.py +0 -19
  63. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_text_analytics_client.py +0 -97
  64. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/_vendor.py +0 -27
  65. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/operations/_patch.py +0 -121
  66. azure/ai/textanalytics/_generated/v2022_10_01_preview/aio/operations/_text_analytics_client_operations.py +0 -603
  67. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/__init__.py +0 -407
  68. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_models_py3.py +0 -8462
  69. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_patch.py +0 -72
  70. azure/ai/textanalytics/_generated/v2022_10_01_preview/models/_text_analytics_client_enums.py +0 -730
  71. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/__init__.py +0 -18
  72. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/_patch.py +0 -120
  73. azure/ai/textanalytics/_generated/v2022_10_01_preview/operations/_text_analytics_client_operations.py +0 -744
  74. azure/ai/textanalytics/_generated/v3_0/__init__.py +0 -20
  75. azure/ai/textanalytics/_generated/v3_0/_configuration.py +0 -66
  76. azure/ai/textanalytics/_generated/v3_0/_patch.py +0 -31
  77. azure/ai/textanalytics/_generated/v3_0/_text_analytics_client.py +0 -96
  78. azure/ai/textanalytics/_generated/v3_0/_vendor.py +0 -33
  79. azure/ai/textanalytics/_generated/v3_0/aio/__init__.py +0 -20
  80. azure/ai/textanalytics/_generated/v3_0/aio/_configuration.py +0 -65
  81. azure/ai/textanalytics/_generated/v3_0/aio/_patch.py +0 -31
  82. azure/ai/textanalytics/_generated/v3_0/aio/_text_analytics_client.py +0 -93
  83. azure/ai/textanalytics/_generated/v3_0/aio/_vendor.py +0 -27
  84. azure/ai/textanalytics/_generated/v3_0/aio/operations/__init__.py +0 -18
  85. azure/ai/textanalytics/_generated/v3_0/aio/operations/_patch.py +0 -19
  86. azure/ai/textanalytics/_generated/v3_0/aio/operations/_text_analytics_client_operations.py +0 -428
  87. azure/ai/textanalytics/_generated/v3_0/models/__init__.py +0 -81
  88. azure/ai/textanalytics/_generated/v3_0/models/_models_py3.py +0 -1467
  89. azure/ai/textanalytics/_generated/v3_0/models/_patch.py +0 -19
  90. azure/ai/textanalytics/_generated/v3_0/models/_text_analytics_client_enums.py +0 -58
  91. azure/ai/textanalytics/_generated/v3_0/operations/__init__.py +0 -18
  92. azure/ai/textanalytics/_generated/v3_0/operations/_patch.py +0 -19
  93. azure/ai/textanalytics/_generated/v3_0/operations/_text_analytics_client_operations.py +0 -604
  94. azure/ai/textanalytics/_generated/v3_1/__init__.py +0 -20
  95. azure/ai/textanalytics/_generated/v3_1/_configuration.py +0 -66
  96. azure/ai/textanalytics/_generated/v3_1/_patch.py +0 -31
  97. azure/ai/textanalytics/_generated/v3_1/_text_analytics_client.py +0 -98
  98. azure/ai/textanalytics/_generated/v3_1/_vendor.py +0 -45
  99. azure/ai/textanalytics/_generated/v3_1/aio/__init__.py +0 -20
  100. azure/ai/textanalytics/_generated/v3_1/aio/_configuration.py +0 -65
  101. azure/ai/textanalytics/_generated/v3_1/aio/_patch.py +0 -31
  102. azure/ai/textanalytics/_generated/v3_1/aio/_text_analytics_client.py +0 -95
  103. azure/ai/textanalytics/_generated/v3_1/aio/_vendor.py +0 -27
  104. azure/ai/textanalytics/_generated/v3_1/aio/operations/__init__.py +0 -18
  105. azure/ai/textanalytics/_generated/v3_1/aio/operations/_patch.py +0 -19
  106. azure/ai/textanalytics/_generated/v3_1/aio/operations/_text_analytics_client_operations.py +0 -1291
  107. azure/ai/textanalytics/_generated/v3_1/models/__init__.py +0 -205
  108. azure/ai/textanalytics/_generated/v3_1/models/_models_py3.py +0 -3976
  109. azure/ai/textanalytics/_generated/v3_1/models/_patch.py +0 -19
  110. azure/ai/textanalytics/_generated/v3_1/models/_text_analytics_client_enums.py +0 -367
  111. azure/ai/textanalytics/_generated/v3_1/operations/__init__.py +0 -18
  112. azure/ai/textanalytics/_generated/v3_1/operations/_patch.py +0 -19
  113. azure/ai/textanalytics/_generated/v3_1/operations/_text_analytics_client_operations.py +0 -1709
  114. azure/ai/textanalytics/_lro.py +0 -552
  115. azure/ai/textanalytics/_models.py +0 -3142
  116. azure/ai/textanalytics/_policies.py +0 -66
  117. azure/ai/textanalytics/_request_handlers.py +0 -104
  118. azure/ai/textanalytics/_response_handlers.py +0 -580
  119. azure/ai/textanalytics/_text_analytics_client.py +0 -1802
  120. azure/ai/textanalytics/_user_agent.py +0 -8
  121. azure/ai/textanalytics/_validate.py +0 -113
  122. azure/ai/textanalytics/aio/_base_client_async.py +0 -95
  123. azure/ai/textanalytics/aio/_lro_async.py +0 -501
  124. azure/ai/textanalytics/aio/_response_handlers_async.py +0 -94
  125. azure/ai/textanalytics/aio/_text_analytics_client_async.py +0 -1800
  126. azure_ai_textanalytics-5.3.0b1.dist-info/RECORD +0 -115
  127. {azure_ai_textanalytics-5.3.0b1.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info/licenses}/LICENSE +0 -0
  128. {azure_ai_textanalytics-5.3.0b1.dist-info → azure_ai_textanalytics-6.0.0b1.dist-info}/top_level.txt +0 -0
@@ -1,501 +0,0 @@
1
- # ------------------------------------
2
- # Copyright (c) Microsoft Corporation.
3
- # Licensed under the MIT License.
4
- # ------------------------------------
5
-
6
- import base64
7
- import functools
8
- import json
9
- from typing import Mapping, Any, TypeVar, Generator, Awaitable, cast
10
- from typing_extensions import Protocol, runtime_checkable
11
- from azure.core.exceptions import HttpResponseError
12
- from azure.core.polling import AsyncLROPoller
13
- from azure.core.polling.base_polling import OperationFailed, BadStatus
14
- from azure.core.polling.async_base_polling import AsyncLROBasePolling
15
- from azure.core.tracing.decorator_async import distributed_trace_async
16
- from .._lro import TextAnalyticsOperationResourcePolling
17
-
18
- _FINISHED = frozenset(["succeeded", "cancelled", "failed", "partiallycompleted", "partiallysucceeded"])
19
- _FAILED = frozenset(["failed"])
20
- _SUCCEEDED = frozenset(["succeeded", "partiallycompleted", "partiallysucceeded"])
21
-
22
- PollingReturnType = TypeVar("PollingReturnType")
23
- PollingReturnType_co = TypeVar("PollingReturnType_co", covariant=True)
24
-
25
-
26
- @runtime_checkable
27
- class AsyncTextAnalysisLROPoller(Protocol[PollingReturnType_co], Awaitable):
28
- """Implements a protocol which returned poller objects are consistent with.
29
- """
30
-
31
- @property
32
- def details(self) -> Mapping[str, Any]:
33
- """Long-running operation metadata.
34
-
35
- :return: A mapping of details about the long-running operation.
36
- :rtype: Mapping[str, Any]
37
- """
38
- ...
39
-
40
- def continuation_token(self) -> str: # pylint: disable=no-self-use
41
- """Return a continuation token that allows to restart the poller later.
42
-
43
- :returns: An opaque continuation token
44
- :rtype: str
45
- """
46
- ...
47
-
48
- def status(self) -> str: # pylint: disable=no-self-use
49
- """Returns the current status string.
50
-
51
- :returns: The current status string
52
- :rtype: str
53
- """
54
- ...
55
-
56
- async def result(self) -> PollingReturnType_co:
57
- """Return the result of the long running operation.
58
-
59
- :returns: The deserialized resource of the long running operation, if one is available.
60
- :raises ~azure.core.exceptions.HttpResponseError: Server problem with the query.
61
- """
62
- ...
63
-
64
- async def wait(self) -> None:
65
- """Wait on the long running operation.
66
-
67
- :raises ~azure.core.exceptions.HttpResponseError: Server problem with the query.
68
- """
69
- ...
70
-
71
- def done(self) -> bool: # pylint: disable=no-self-use
72
- """Check status of the long running operation.
73
-
74
- :returns: 'True' if the process has completed, else 'False'.
75
- :rtype: bool
76
- """
77
- ...
78
-
79
- def __await__(self) -> Generator[Any, None, PollingReturnType_co]:
80
- ...
81
-
82
- async def cancel(self) -> None: # pylint: disable=no-self-use
83
- """Cancel the operation currently being polled.
84
-
85
- :return: None
86
- :rtype: None
87
- :raises ~azure.core.exceptions.HttpResponseError: When the operation has already reached a terminal state.
88
- """
89
- ...
90
-
91
-
92
- class TextAnalyticsAsyncLROPollingMethod(AsyncLROBasePolling):
93
- def finished(self):
94
- """Is this polling finished?
95
- :rtype: bool
96
- """
97
- return TextAnalyticsAsyncLROPollingMethod._finished(self.status())
98
-
99
- @staticmethod
100
- def _finished(status):
101
- if hasattr(status, "value"):
102
- status = status.value
103
- return str(status).lower() in _FINISHED
104
-
105
- @staticmethod
106
- def _failed(status):
107
- if hasattr(status, "value"):
108
- status = status.value
109
- return str(status).lower() in _FAILED
110
-
111
- @staticmethod
112
- def _raise_if_bad_http_status_and_method(response):
113
- """Check response status code is valid.
114
-
115
- Must be 200, 201, 202, or 204.
116
-
117
- :raises: BadStatus if invalid status.
118
- """
119
- code = response.status_code
120
- if code in {200, 201, 202, 204}:
121
- return
122
- raise BadStatus(
123
- "Invalid return status {!r} for {!r} operation".format(
124
- code, response.request.method
125
- )
126
- )
127
-
128
- async def _poll(self): # pylint:disable=invalid-overridden-method
129
- """Poll status of operation so long as operation is incomplete and
130
- we have an endpoint to query.
131
-
132
- :param callable update_cmd: The function to call to retrieve the
133
- latest status of the long running operation.
134
- :raises: OperationFailed if operation status 'Failed' or 'Canceled'.
135
- :raises: BadStatus if response status invalid.
136
- :raises: BadResponse if response invalid.
137
- """
138
- while not self.finished():
139
- await self._delay()
140
- await self.update_status()
141
-
142
- if TextAnalyticsAsyncLROPollingMethod._failed(self.status()):
143
- try:
144
- job = json.loads(self._pipeline_response.http_response.text())
145
- error_message = ""
146
- for err in job["errors"]:
147
- error_message += "({}) {}".format(err["code"], err["message"])
148
- raise HttpResponseError(message=error_message, response=self._pipeline_response.http_response)
149
- except KeyError as e:
150
- raise OperationFailed("Operation failed or canceled") from e
151
-
152
- final_get_url = self._operation.get_final_get_url(self._pipeline_response)
153
- if final_get_url:
154
- self._pipeline_response = await self.request_status(final_get_url)
155
- TextAnalyticsAsyncLROPollingMethod._raise_if_bad_http_status_and_method(
156
- self._pipeline_response.http_response
157
- )
158
-
159
-
160
- class AsyncAnalyzeHealthcareEntitiesLROPollingMethod(
161
- TextAnalyticsAsyncLROPollingMethod
162
- ):
163
- def __init__(self, *args, **kwargs):
164
- self._text_analytics_client = kwargs.pop("text_analytics_client")
165
- self._doc_id_order = kwargs.pop("doc_id_order", None)
166
- self._show_stats = kwargs.pop("show_stats", None)
167
- super().__init__(
168
- *args, **kwargs
169
- )
170
-
171
- @property
172
- def _current_body(self):
173
- from .._generated.models import JobState
174
- return JobState.deserialize(self._pipeline_response)
175
-
176
- @property
177
- def created_on(self):
178
- if not self._current_body:
179
- return None
180
- return self._current_body.created_date_time
181
-
182
- @property
183
- def expires_on(self):
184
- if not self._current_body:
185
- return None
186
- return self._current_body.expiration_date_time
187
-
188
- @property
189
- def last_modified_on(self):
190
- if not self._current_body:
191
- return None
192
- return self._current_body.last_update_date_time
193
-
194
- @property
195
- def id(self):
196
- if self._current_body and self._current_body.job_id is not None:
197
- return self._current_body.job_id
198
- return self._get_id_from_headers()
199
-
200
- def _get_id_from_headers(self) -> str:
201
- return self._initial_response.http_response.headers[
202
- "Operation-Location"
203
- ].split("/jobs/")[1].split("?")[0]
204
-
205
- @property
206
- def display_name(self):
207
- if not self._current_body:
208
- return None
209
- return self._current_body.display_name
210
-
211
- def get_continuation_token(self):
212
- # type() -> str
213
- import pickle
214
- self._initial_response.context.options["doc_id_order"] = self._doc_id_order
215
- self._initial_response.context.options["show_stats"] = self._show_stats
216
- return base64.b64encode(pickle.dumps(self._initial_response)).decode('ascii')
217
-
218
-
219
- class AsyncAnalyzeHealthcareEntitiesLROPoller(AsyncLROPoller[PollingReturnType]):
220
- def polling_method(self) -> AsyncAnalyzeHealthcareEntitiesLROPollingMethod: # type: ignore
221
- """Return the polling method associated to this poller.
222
-
223
- :return: AsyncAnalyzeHealthcareEntitiesLROPollingMethod
224
- :rtype: AsyncAnalyzeHealthcareEntitiesLROPollingMethod
225
- """
226
- return self._polling_method # type: ignore
227
-
228
- @property
229
- def details(self) -> Mapping[str, Any]:
230
- """Long-running operation metadata.
231
-
232
- :return: A mapping of details about the long-running operation.
233
- :rtype: Mapping[str, Any]
234
- """
235
- return {
236
- "id": self.polling_method().id,
237
- "created_on": self.polling_method().created_on,
238
- "expires_on": self.polling_method().expires_on,
239
- "display_name": self.polling_method().display_name,
240
- "last_modified_on": self.polling_method().last_modified_on,
241
- }
242
-
243
- def __getattr__(self, item):
244
- attrs = [
245
- "created_on",
246
- "expires_on",
247
- "display_name",
248
- "last_modified_on",
249
- "id"
250
- ]
251
- if item in attrs:
252
- return self.details[item]
253
- return self.__getattribute__(item)
254
-
255
- @classmethod
256
- def from_continuation_token( # type: ignore
257
- cls,
258
- polling_method: AsyncAnalyzeHealthcareEntitiesLROPollingMethod,
259
- continuation_token: str,
260
- **kwargs: Any
261
- ) -> "AsyncAnalyzeHealthcareEntitiesLROPoller":
262
- """Internal use only.
263
-
264
- :param polling_method: Polling method to use.
265
- :type polling_method: AsyncAnalyzeHealthcareEntitiesLROPollingMethod
266
- :param str continuation_token: Opaque token.
267
- :return: AsyncAnalyzeHealthcareEntitiesLROPoller
268
- :rtype: AsyncAnalyzeHealthcareEntitiesLROPoller
269
-
270
- :meta private:
271
- """
272
- client, initial_response, deserialization_callback = polling_method.from_continuation_token(
273
- continuation_token, **kwargs
274
- )
275
- polling_method._lro_algorithms = [ # pylint: disable=protected-access
276
- TextAnalyticsOperationResourcePolling(
277
- show_stats=initial_response.context.options["show_stats"]
278
- )
279
- ]
280
- return cls(
281
- client,
282
- initial_response,
283
- functools.partial(deserialization_callback, initial_response),
284
- polling_method # type: ignore
285
- )
286
-
287
- @distributed_trace_async
288
- async def cancel(self, **kwargs) -> "AsyncLROPoller[None]": # type: ignore
289
- """Cancel the operation currently being polled.
290
-
291
- :keyword int polling_interval: The polling interval to use to poll the cancellation status.
292
- The default value is 5 seconds.
293
- :return: Returns an instance of an AsyncLROPoller that returns None.
294
- :rtype: ~azure.core.polling.AsyncLROPoller[None]
295
- :raises ~azure.core.exceptions.HttpResponseError: When the operation has already reached a terminal state.
296
-
297
- .. admonition:: Example:
298
-
299
- .. literalinclude:: ../samples/async_samples/sample_analyze_healthcare_entities_with_cancellation_async.py
300
- :start-after: [START analyze_healthcare_entities_with_cancellation_async]
301
- :end-before: [END analyze_healthcare_entities_with_cancellation_async]
302
- :language: python
303
- :dedent: 4
304
- :caption: Cancel an existing health operation.
305
- """
306
- polling_interval = kwargs.pop("polling_interval", 5)
307
-
308
- try:
309
- client = getattr(
310
- self._polling_method, "_text_analytics_client"
311
- )
312
- try:
313
- return await client.begin_cancel_health_job(
314
- self.id, polling=TextAnalyticsAsyncLROPollingMethod(timeout=polling_interval)
315
- )
316
- except ValueError: # language API compat
317
- return await client.begin_analyze_text_cancel_job(
318
- self.id, polling=TextAnalyticsAsyncLROPollingMethod(timeout=polling_interval)
319
- )
320
- except HttpResponseError as error:
321
- from .._response_handlers import process_http_response_error
322
-
323
- process_http_response_error(error)
324
-
325
-
326
- class AsyncAnalyzeActionsLROPollingMethod(TextAnalyticsAsyncLROPollingMethod):
327
- def __init__(self, *args, **kwargs):
328
- self._doc_id_order = kwargs.pop("doc_id_order", None)
329
- self._task_id_order = kwargs.pop("task_id_order", None)
330
- self._show_stats = kwargs.pop("show_stats", None)
331
- self._text_analytics_client = kwargs.pop("text_analytics_client", None)
332
- super().__init__(*args, **kwargs)
333
-
334
- @property
335
- def _current_body(self):
336
- from .._generated.models import JobState
337
- return JobState.deserialize(self._pipeline_response)
338
-
339
- @property
340
- def created_on(self):
341
- if not self._current_body:
342
- return None
343
- return self._current_body.created_date_time
344
-
345
- @property
346
- def display_name(self):
347
- if not self._current_body:
348
- return None
349
- return self._current_body.display_name
350
-
351
- @property
352
- def expires_on(self):
353
- if not self._current_body:
354
- return None
355
- return self._current_body.expiration_date_time
356
-
357
- @property
358
- def actions_failed_count(self):
359
- if not self._current_body:
360
- return None
361
- return self._current_body.additional_properties.get("tasks", {}).get("failed", None)
362
-
363
- @property
364
- def actions_in_progress_count(self):
365
- if not self._current_body:
366
- return None
367
- return self._current_body.additional_properties.get("tasks", {}).get("inProgress", None)
368
-
369
- @property
370
- def actions_succeeded_count(self):
371
- if not self._current_body:
372
- return None
373
- return self._current_body.additional_properties.get("tasks", {}).get("completed", None)
374
-
375
- @property
376
- def last_modified_on(self):
377
- if not self._current_body:
378
- return None
379
- return self._current_body.last_update_date_time
380
-
381
- @property
382
- def total_actions_count(self):
383
- if not self._current_body:
384
- return None
385
- return self._current_body.additional_properties.get("tasks", {}).get("total", None)
386
-
387
- @property
388
- def id(self):
389
- if self._current_body and self._current_body.job_id is not None:
390
- return self._current_body.job_id
391
- return self._get_id_from_headers()
392
-
393
- def _get_id_from_headers(self) -> str:
394
- return self._initial_response.http_response.headers[
395
- "Operation-Location"
396
- ].split("/jobs/")[1].split("?")[0]
397
-
398
- def get_continuation_token(self):
399
- # type: () -> str
400
- import pickle
401
- self._initial_response.context.options["doc_id_order"] = self._doc_id_order
402
- self._initial_response.context.options["task_id_order"] = self._task_id_order
403
- self._initial_response.context.options["show_stats"] = self._show_stats
404
- return base64.b64encode(pickle.dumps(self._initial_response)).decode('ascii')
405
-
406
-
407
- class AsyncAnalyzeActionsLROPoller(AsyncLROPoller[PollingReturnType]):
408
- def polling_method(self) -> AsyncAnalyzeActionsLROPollingMethod: # type: ignore
409
- """Return the polling method associated to this poller.
410
-
411
- :return: AsyncAnalyzeActionsLROPollingMethod
412
- :rtype: AsyncAnalyzeActionsLROPollingMethod
413
- """
414
- return self._polling_method # type: ignore
415
-
416
- @property
417
- def details(self) -> Mapping[str, Any]:
418
- """Long-running operation metadata.
419
-
420
- :return: A mapping of details about the long-running operation.
421
- :rtype: Mapping[str, Any]
422
- """
423
- return {
424
- "id": self.polling_method().id,
425
- "created_on": self.polling_method().created_on,
426
- "expires_on": self.polling_method().expires_on,
427
- "display_name": self.polling_method().display_name,
428
- "last_modified_on": self.polling_method().last_modified_on,
429
- "actions_failed_count": self.polling_method().actions_failed_count,
430
- "actions_in_progress_count": self.polling_method().actions_in_progress_count,
431
- "actions_succeeded_count": self.polling_method().actions_succeeded_count,
432
- "total_actions_count": self.polling_method().total_actions_count,
433
- }
434
-
435
- def __getattr__(self, item):
436
- attrs = [
437
- "created_on",
438
- "expires_on",
439
- "display_name",
440
- "actions_failed_count",
441
- "actions_in_progress_count",
442
- "actions_succeeded_count",
443
- "total_actions_count",
444
- "last_modified_on",
445
- "id"
446
- ]
447
- if item in attrs:
448
- return self.details[item]
449
- return self.__getattribute__(item)
450
-
451
- @classmethod
452
- def from_continuation_token( # type: ignore
453
- cls,
454
- polling_method: AsyncAnalyzeActionsLROPollingMethod,
455
- continuation_token: str,
456
- **kwargs: Any
457
- ) -> "AsyncAnalyzeActionsLROPoller": # type: ignore
458
- """Internal use only.
459
-
460
- :param polling_method: Polling method to use.
461
- :type polling_method: AsyncAnalyzeActionsLROPollingMethod
462
- :param str continuation_token: Opaque token.
463
- :return: AsyncAnalyzeActionsLROPoller
464
- :rtype: AsyncAnalyzeActionsLROPoller
465
-
466
- :meta private:
467
- """
468
- client, initial_response, deserialization_callback = polling_method.from_continuation_token(
469
- continuation_token, **kwargs
470
- )
471
- polling_method._lro_algorithms = [ # pylint: disable=protected-access
472
- TextAnalyticsOperationResourcePolling(
473
- show_stats=initial_response.context.options["show_stats"]
474
- )
475
- ]
476
- return cls(
477
- client,
478
- initial_response,
479
- functools.partial(deserialization_callback, initial_response),
480
- polling_method # type: ignore
481
- )
482
-
483
- @distributed_trace_async
484
- async def cancel(self) -> None:
485
- """Cancel the operation currently being polled.
486
-
487
- :return: None
488
- :rtype: None
489
- :raises ~azure.core.exceptions.HttpResponseError: When the operation has already reached a terminal state.
490
- """
491
-
492
- cast(AsyncAnalyzeActionsLROPollingMethod, self.polling_method)
493
- client = self.polling_method()._text_analytics_client # pylint: disable=protected-access
494
-
495
- try:
496
- await client.begin_analyze_text_cancel_job(self.id, polling=False)
497
- except ValueError:
498
- raise ValueError("Cancellation not supported by API versions v3.0, v3.1.")
499
- except HttpResponseError as error:
500
- from .._response_handlers import process_http_response_error
501
- process_http_response_error(error)
@@ -1,94 +0,0 @@
1
- # ------------------------------------
2
- # Copyright (c) Microsoft Corporation.
3
- # Licensed under the MIT License.
4
- # ------------------------------------
5
-
6
-
7
- import functools
8
- from urllib.parse import urlparse, parse_qsl
9
-
10
- from azure.core.async_paging import AsyncList, AsyncItemPaged
11
- from .._response_handlers import healthcare_result, get_iter_items
12
-
13
-
14
- async def healthcare_extract_page_data_async(
15
- doc_id_order, obj, health_job_state
16
- ): # pylint: disable=unused-argument
17
- return (
18
- health_job_state.next_link,
19
- healthcare_result(
20
- doc_id_order,
21
- health_job_state.results
22
- if hasattr(health_job_state, "results")
23
- else health_job_state.tasks.items[0].results,
24
- {},
25
- lro=True
26
- ),
27
- )
28
-
29
-
30
- async def lro_get_next_page_async(
31
- lro_status_callback, first_page, continuation_token, show_stats=False
32
- ):
33
- if continuation_token is None:
34
- return first_page
35
-
36
- try:
37
- continuation_token = continuation_token.decode("utf-8")
38
-
39
- except AttributeError:
40
- pass
41
-
42
- parsed_url = urlparse(continuation_token)
43
- job_id = parsed_url.path.split("/")[-1]
44
- query_params = dict(parse_qsl(parsed_url.query.replace("$", "")))
45
- if "showStats" in query_params:
46
- query_params.pop("showStats")
47
- if "api-version" in query_params: # language api compat
48
- query_params.pop("api-version")
49
- query_params["show_stats"] = show_stats
50
-
51
- return await lro_status_callback(job_id, **query_params)
52
-
53
-
54
- def healthcare_paged_result(
55
- doc_id_order,
56
- health_status_callback,
57
- _,
58
- obj,
59
- show_stats=False,
60
- ):
61
- return AsyncItemPaged(
62
- functools.partial(
63
- lro_get_next_page_async, health_status_callback, obj, show_stats=show_stats
64
- ),
65
- functools.partial(
66
- healthcare_extract_page_data_async, doc_id_order, obj
67
- ),
68
- )
69
-
70
-
71
- async def analyze_extract_page_data_async(
72
- doc_id_order, task_order, bespoke, analyze_job_state
73
- ):
74
- iter_items = get_iter_items(
75
- doc_id_order, task_order, bespoke, analyze_job_state
76
- )
77
- return analyze_job_state.next_link, AsyncList(iter_items)
78
-
79
-
80
- def analyze_paged_result(
81
- doc_id_order,
82
- task_order,
83
- analyze_status_callback,
84
- _,
85
- obj,
86
- show_stats=False,
87
- bespoke=False
88
- ):
89
- return AsyncItemPaged(
90
- functools.partial(lro_get_next_page_async, analyze_status_callback, obj, show_stats=show_stats),
91
- functools.partial(
92
- analyze_extract_page_data_async, doc_id_order, task_order, bespoke
93
- ),
94
- )