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,552 +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 urllib.parse import urlencode
10
- from typing import Any, Mapping, Optional, Callable, TypeVar, cast
11
- from typing_extensions import Protocol, runtime_checkable
12
- from azure.core.exceptions import HttpResponseError
13
- from azure.core.tracing.decorator import distributed_trace
14
- from azure.core.polling import LROPoller
15
- from azure.core.polling.base_polling import (
16
- LROBasePolling,
17
- OperationResourcePolling,
18
- OperationFailed,
19
- BadStatus,
20
- )
21
-
22
- _FINISHED = frozenset(["succeeded", "cancelled", "failed", "partiallycompleted", "partiallysucceeded"])
23
- _FAILED = frozenset(["failed"])
24
- _SUCCEEDED = frozenset(["succeeded", "partiallycompleted", "partiallysucceeded"])
25
-
26
-
27
- PollingReturnType = TypeVar("PollingReturnType")
28
- PollingReturnType_co = TypeVar("PollingReturnType_co", covariant=True)
29
-
30
-
31
- @runtime_checkable
32
- class TextAnalysisLROPoller(Protocol[PollingReturnType_co]):
33
- """Implements a protocol which returned poller objects are consistent with.
34
- """
35
-
36
- @property
37
- def details(self) -> Mapping[str, Any]:
38
- """Long-running operation metadata.
39
-
40
- :return: A mapping of details about the long-running operation.
41
- :rtype: Mapping[str, Any]
42
- """
43
- ...
44
-
45
- def continuation_token(self) -> str: # pylint: disable=no-self-use
46
- """Return a continuation token that allows to restart the poller later.
47
-
48
- :returns: An opaque continuation token
49
- :rtype: str
50
- """
51
- ...
52
-
53
- def status(self) -> str: # pylint: disable=no-self-use
54
- """Returns the current status string.
55
-
56
- :returns: The current status string
57
- :rtype: str
58
- """
59
- ...
60
-
61
- # pylint: disable=no-self-use, unused-argument
62
- def result(self, timeout: Optional[int] = None) -> PollingReturnType_co:
63
- """Return the result of the long running operation, or
64
- the result available after the specified timeout.
65
-
66
- :returns: The deserialized resource of the long running operation,
67
- if one is available.
68
- :raises ~azure.core.exceptions.HttpResponseError: Server problem with the query.
69
- """
70
- ...
71
-
72
- def wait(self, timeout: Optional[float] = None) -> None: # pylint: disable=no-self-use, unused-argument
73
- """Wait on the long running operation for a specified length
74
- of time. You can check if this call as ended with timeout with the
75
- "done()" method.
76
-
77
- :param float timeout: Period of time to wait for the long running
78
- operation to complete (in seconds).
79
- :raises ~azure.core.exceptions.HttpResponseError: Server problem with the query.
80
- """
81
- ...
82
-
83
- def done(self) -> bool: # pylint: disable=no-self-use
84
- """Check status of the long running operation.
85
-
86
- :returns: 'True' if the process has completed, else 'False'.
87
- :rtype: bool
88
- """
89
- ...
90
-
91
- def add_done_callback(self, func: Callable) -> None: # pylint: disable=no-self-use, unused-argument
92
- """Add callback function to be run once the long running operation
93
- has completed - regardless of the status of the operation.
94
-
95
- :param callable func: Callback function that takes at least one
96
- argument, a completed LongRunningOperation.
97
- """
98
- ...
99
-
100
- def remove_done_callback(self, func: Callable) -> None: # pylint: disable=no-self-use, unused-argument
101
- """Remove a callback from the long running operation.
102
-
103
- :param callable func: The function to be removed from the callbacks.
104
- :raises ValueError: if the long running operation has already completed.
105
- """
106
- ...
107
-
108
- def cancel(self) -> None: # pylint: disable=no-self-use
109
- """Cancel the operation currently being polled.
110
-
111
- :return: None
112
- :rtype: None
113
- :raises ~azure.core.exceptions.HttpResponseError: When the operation has already reached a terminal state.
114
- """
115
- ...
116
-
117
-
118
- class TextAnalyticsOperationResourcePolling(OperationResourcePolling):
119
- def __init__(
120
- self, operation_location_header="operation-location", show_stats=False
121
- ):
122
- super().__init__(
123
- operation_location_header=operation_location_header
124
- )
125
- self._show_stats = show_stats
126
- self._query_params = {"showStats": show_stats}
127
-
128
- def get_polling_url(self):
129
- if not self._show_stats:
130
- return super().get_polling_url()
131
-
132
- # language api compat
133
- delimiter = "&" if super().get_polling_url().find("?") != -1 else "?"
134
-
135
- return (
136
- super().get_polling_url()
137
- + delimiter
138
- + urlencode(self._query_params)
139
- )
140
-
141
-
142
- class TextAnalyticsLROPollingMethod(LROBasePolling):
143
- def finished(self):
144
- """Is this polling finished?
145
-
146
- :rtype: bool
147
- """
148
- return TextAnalyticsLROPollingMethod._finished(self.status())
149
-
150
- @staticmethod
151
- def _finished(status):
152
- if hasattr(status, "value"):
153
- status = status.value
154
- return str(status).lower() in _FINISHED
155
-
156
- @staticmethod
157
- def _failed(status):
158
- if hasattr(status, "value"):
159
- status = status.value
160
- return str(status).lower() in _FAILED
161
-
162
- @staticmethod
163
- def _raise_if_bad_http_status_and_method(response):
164
- """Check response status code is valid.
165
-
166
- Must be 200, 201, 202, or 204.
167
-
168
- :raises: BadStatus if invalid status.
169
- """
170
- code = response.status_code
171
- if code in {200, 201, 202, 204}:
172
- return
173
- raise BadStatus(
174
- "Invalid return status {!r} for {!r} operation".format(
175
- code, response.request.method
176
- )
177
- )
178
-
179
- def _poll(self):
180
- """Poll status of operation so long as operation is incomplete and
181
- we have an endpoint to query.
182
-
183
- :param callable update_cmd: The function to call to retrieve the
184
- latest status of the long running operation.
185
- :raises: OperationFailed if operation status 'Failed' or 'Canceled'.
186
- :raises: BadStatus if response status invalid.
187
- :raises: BadResponse if response invalid.
188
- """
189
-
190
- while not self.finished():
191
- self._delay()
192
- self.update_status()
193
-
194
- if TextAnalyticsLROPollingMethod._failed(self.status()):
195
- try:
196
- job = json.loads(self._pipeline_response.http_response.text())
197
- error_message = ""
198
- for err in job["errors"]:
199
- error_message += "({}) {}".format(err["code"], err["message"])
200
- raise HttpResponseError(message=error_message, response=self._pipeline_response.http_response)
201
- except KeyError as e:
202
- raise OperationFailed("Operation failed or canceled") from e
203
-
204
- final_get_url = self._operation.get_final_get_url(self._pipeline_response)
205
- if final_get_url:
206
- self._pipeline_response = self.request_status(final_get_url)
207
- TextAnalyticsLROPollingMethod._raise_if_bad_http_status_and_method(
208
- self._pipeline_response.http_response
209
- )
210
-
211
-
212
- class AnalyzeHealthcareEntitiesLROPollingMethod(TextAnalyticsLROPollingMethod):
213
- def __init__(self, *args, **kwargs):
214
- self._doc_id_order = kwargs.pop("doc_id_order", None)
215
- self._show_stats = kwargs.pop("show_stats", None)
216
- self._text_analytics_client = kwargs.pop("text_analytics_client")
217
- super().__init__(*args, **kwargs)
218
-
219
- @property
220
- def _current_body(self):
221
- from ._generated.models import JobState
222
- return JobState.deserialize(self._pipeline_response)
223
-
224
- @property
225
- def created_on(self):
226
- if not self._current_body:
227
- return None
228
- return self._current_body.created_date_time
229
-
230
- @property
231
- def expires_on(self):
232
- if not self._current_body:
233
- return None
234
- return self._current_body.expiration_date_time
235
-
236
- @property
237
- def last_modified_on(self):
238
- if not self._current_body:
239
- return None
240
- return self._current_body.last_update_date_time
241
-
242
- @property
243
- def id(self):
244
- if self._current_body and self._current_body.job_id is not None:
245
- return self._current_body.job_id
246
- return self._get_id_from_headers()
247
-
248
- def _get_id_from_headers(self) -> str:
249
- return self._initial_response.http_response.headers[
250
- "Operation-Location"
251
- ].split("/jobs/")[1].split("?")[0]
252
-
253
- @property
254
- def display_name(self):
255
- if not self._current_body:
256
- return None
257
- return self._current_body.display_name
258
-
259
- def get_continuation_token(self):
260
- # type: () -> str
261
- import pickle
262
- self._initial_response.context.options["doc_id_order"] = self._doc_id_order
263
- self._initial_response.context.options["show_stats"] = self._show_stats
264
- return base64.b64encode(pickle.dumps(self._initial_response)).decode('ascii')
265
-
266
-
267
- class AnalyzeHealthcareEntitiesLROPoller(LROPoller[PollingReturnType]):
268
- def polling_method(self) -> AnalyzeHealthcareEntitiesLROPollingMethod:
269
- """Return the polling method associated to this poller.
270
-
271
- :return: AnalyzeHealthcareEntitiesLROPollingMethod
272
- :rtype: AnalyzeHealthcareEntitiesLROPollingMethod
273
- """
274
- return self._polling_method # type: ignore
275
-
276
- @property
277
- def details(self) -> Mapping[str, Any]:
278
- """Long-running operation metadata.
279
-
280
- :return: A mapping of details about the long-running operation.
281
- :rtype: Mapping[str, Any]
282
- """
283
- return {
284
- "id": self.polling_method().id,
285
- "created_on": self.polling_method().created_on,
286
- "expires_on": self.polling_method().expires_on,
287
- "display_name": self.polling_method().display_name,
288
- "last_modified_on": self.polling_method().last_modified_on,
289
- }
290
-
291
- def __getattr__(self, item):
292
- attrs = [
293
- "created_on",
294
- "expires_on",
295
- "display_name",
296
- "last_modified_on",
297
- "id"
298
- ]
299
- if item in attrs:
300
- return self.details[item]
301
- return self.__getattribute__(item)
302
-
303
- @classmethod
304
- def from_continuation_token( # type: ignore
305
- cls,
306
- polling_method: AnalyzeHealthcareEntitiesLROPollingMethod,
307
- continuation_token: str,
308
- **kwargs: Any
309
- ) -> "AnalyzeHealthcareEntitiesLROPoller": # type: ignore
310
- """Internal use only.
311
-
312
- :param polling_method: Polling method to use.
313
- :type polling_method: AnalyzeHealthcareEntitiesLROPollingMethod
314
- :param str continuation_token: Opaque token.
315
- :return: AnalyzeHealthcareEntitiesLROPoller
316
- :rtype: AnalyzeHealthcareEntitiesLROPoller
317
-
318
- :meta private:
319
- """
320
- client, initial_response, deserialization_callback = polling_method.from_continuation_token(
321
- continuation_token, **kwargs
322
- )
323
- polling_method._lro_algorithms = [ # pylint: disable=protected-access
324
- TextAnalyticsOperationResourcePolling(
325
- show_stats=initial_response.context.options["show_stats"]
326
- )
327
- ]
328
- return cls(
329
- client,
330
- initial_response,
331
- functools.partial(deserialization_callback, initial_response),
332
- polling_method
333
- )
334
-
335
- @distributed_trace
336
- def cancel(self, **kwargs: Any) -> LROPoller[None]: # type: ignore
337
- """Cancel the operation currently being polled.
338
-
339
- :keyword int polling_interval: The polling interval to use to poll the cancellation status.
340
- The default value is 5 seconds.
341
- :return: Returns an instance of an LROPoller that returns None.
342
- :rtype: ~azure.core.polling.LROPoller[None]
343
- :raises ~azure.core.exceptions.HttpResponseError: When the operation has already reached a terminal state.
344
-
345
- .. admonition:: Example:
346
-
347
- .. literalinclude:: ../samples/sample_analyze_healthcare_entities_with_cancellation.py
348
- :start-after: [START analyze_healthcare_entities_with_cancellation]
349
- :end-before: [END analyze_healthcare_entities_with_cancellation]
350
- :language: python
351
- :dedent: 4
352
- :caption: Cancel an existing health operation.
353
- """
354
- polling_interval = kwargs.pop("polling_interval", 5)
355
-
356
- try:
357
- # Join the thread so we no longer have to wait for a result from it.
358
- getattr(self, "_thread").join(timeout=0)
359
-
360
- client = getattr(
361
- self._polling_method, "_text_analytics_client"
362
- )
363
- try:
364
- return client.begin_cancel_health_job(
365
- self.id, polling=TextAnalyticsLROPollingMethod(timeout=polling_interval)
366
- )
367
- except ValueError: # language API compat
368
- return client.begin_analyze_text_cancel_job(
369
- self.id, polling=TextAnalyticsLROPollingMethod(timeout=polling_interval)
370
- )
371
- except HttpResponseError as error:
372
- from ._response_handlers import process_http_response_error
373
-
374
- process_http_response_error(error)
375
-
376
-
377
- class AnalyzeActionsLROPollingMethod(TextAnalyticsLROPollingMethod):
378
- def __init__(self, *args, **kwargs):
379
- self._doc_id_order = kwargs.pop("doc_id_order", None)
380
- self._task_id_order = kwargs.pop("task_id_order", None)
381
- self._show_stats = kwargs.pop("show_stats", None)
382
- self._text_analytics_client = kwargs.pop("text_analytics_client", None)
383
- super().__init__(*args, **kwargs)
384
-
385
- @property
386
- def _current_body(self):
387
- from ._generated.models import JobState
388
- return JobState.deserialize(self._pipeline_response)
389
-
390
- @property
391
- def created_on(self):
392
- if not self._current_body:
393
- return None
394
- return self._current_body.created_date_time
395
-
396
- @property
397
- def expires_on(self):
398
- if not self._current_body:
399
- return None
400
- return self._current_body.expiration_date_time
401
-
402
- @property
403
- def display_name(self):
404
- if not self._current_body:
405
- return None
406
- return self._current_body.display_name
407
-
408
- @property
409
- def actions_failed_count(self):
410
- if not self._current_body:
411
- return None
412
- return self._current_body.additional_properties.get("tasks", {}).get("failed", None)
413
-
414
- @property
415
- def actions_in_progress_count(self):
416
- if not self._current_body:
417
- return None
418
- return self._current_body.additional_properties.get("tasks", {}).get("inProgress", None)
419
-
420
- @property
421
- def actions_succeeded_count(self):
422
- if not self._current_body:
423
- return None
424
- return self._current_body.additional_properties.get("tasks", {}).get("completed", None)
425
-
426
- @property
427
- def last_modified_on(self):
428
- if not self._current_body:
429
- return None
430
- return self._current_body.last_update_date_time
431
-
432
- @property
433
- def total_actions_count(self):
434
- if not self._current_body:
435
- return None
436
- return self._current_body.additional_properties.get("tasks", {}).get("total", None)
437
-
438
- @property
439
- def id(self):
440
- if self._current_body and self._current_body.job_id is not None:
441
- return self._current_body.job_id
442
- return self._get_id_from_headers()
443
-
444
- def _get_id_from_headers(self) -> str:
445
- return self._initial_response.http_response.headers[
446
- "Operation-Location"
447
- ].split("/jobs/")[1].split("?")[0]
448
-
449
- def get_continuation_token(self):
450
- # type: () -> str
451
- import pickle
452
- self._initial_response.context.options["doc_id_order"] = self._doc_id_order
453
- self._initial_response.context.options["task_id_order"] = self._task_id_order
454
- self._initial_response.context.options["show_stats"] = self._show_stats
455
- return base64.b64encode(pickle.dumps(self._initial_response)).decode('ascii')
456
-
457
-
458
- class AnalyzeActionsLROPoller(LROPoller[PollingReturnType]):
459
- def polling_method(self) -> AnalyzeActionsLROPollingMethod:
460
- """Return the polling method associated to this poller.
461
-
462
- :return: AnalyzeActionsLROPollingMethod
463
- :rtype: AnalyzeActionsLROPollingMethod
464
- """
465
- return self._polling_method # type: ignore
466
-
467
- @property
468
- def details(self) -> Mapping[str, Any]:
469
- """Long-running operation metadata.
470
-
471
- :return: A mapping of details about the long-running operation.
472
- :rtype: Mapping[str, Any]
473
- """
474
- return {
475
- "id": self.polling_method().id,
476
- "created_on": self.polling_method().created_on,
477
- "expires_on": self.polling_method().expires_on,
478
- "display_name": self.polling_method().display_name,
479
- "last_modified_on": self.polling_method().last_modified_on,
480
- "actions_failed_count": self.polling_method().actions_failed_count,
481
- "actions_in_progress_count": self.polling_method().actions_in_progress_count,
482
- "actions_succeeded_count": self.polling_method().actions_succeeded_count,
483
- "total_actions_count": self.polling_method().total_actions_count,
484
- }
485
-
486
- def __getattr__(self, item):
487
- attrs = [
488
- "created_on",
489
- "expires_on",
490
- "display_name",
491
- "actions_failed_count",
492
- "actions_in_progress_count",
493
- "actions_succeeded_count",
494
- "total_actions_count",
495
- "last_modified_on",
496
- "id"
497
- ]
498
- if item in attrs:
499
- return self.details[item]
500
- return self.__getattribute__(item)
501
-
502
- @classmethod
503
- def from_continuation_token( # type: ignore
504
- cls,
505
- polling_method: AnalyzeActionsLROPollingMethod,
506
- continuation_token: str,
507
- **kwargs: Any
508
- ) -> "AnalyzeActionsLROPoller": # type: ignore
509
- """Internal use only.
510
-
511
- :param polling_method: Polling method to use.
512
- :type polling_method: AnalyzeActionsLROPollingMethod
513
- :param str continuation_token: Opaque token.
514
- :return: AnalyzeActionsLROPoller
515
- :rtype: AnalyzeActionsLROPoller
516
-
517
- :meta private:
518
- """
519
- client, initial_response, deserialization_callback = polling_method.from_continuation_token(
520
- continuation_token, **kwargs
521
- )
522
- polling_method._lro_algorithms = [ # pylint: disable=protected-access
523
- TextAnalyticsOperationResourcePolling(
524
- show_stats=initial_response.context.options["show_stats"]
525
- )
526
- ]
527
- return cls(
528
- client,
529
- initial_response,
530
- functools.partial(deserialization_callback, initial_response),
531
- polling_method
532
- )
533
-
534
- @distributed_trace
535
- def cancel(self) -> None:
536
- """Cancel the operation currently being polled.
537
-
538
- :return: None
539
- :rtype: None
540
- :raises ~azure.core.exceptions.HttpResponseError: When the operation has already reached a terminal state.
541
- """
542
-
543
- cast(AnalyzeActionsLROPollingMethod, self.polling_method)
544
- client = self.polling_method()._text_analytics_client # pylint: disable=protected-access
545
-
546
- try:
547
- client.begin_analyze_text_cancel_job(self.id, polling=False)
548
- except ValueError:
549
- raise ValueError("Cancellation not supported by API versions v3.0, v3.1.")
550
- except HttpResponseError as error:
551
- from ._response_handlers import process_http_response_error
552
- process_http_response_error(error)