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