-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA autogenerated code for v3.2-preview.1 (#13794)
- Loading branch information
Showing
194 changed files
with
99,763 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_async_lro.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# coding=utf-8 | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
from azure.core.polling.base_polling import OperationFailed, BadStatus | ||
from azure.core.polling.async_base_polling import AsyncLROBasePolling | ||
|
||
|
||
_FINISHED = frozenset(["succeeded", "cancelled", "failed", "partiallysucceeded"]) | ||
_FAILED = frozenset(["failed"]) | ||
_SUCCEEDED = frozenset(["succeeded", "partiallysucceeded"]) | ||
|
||
|
||
class TextAnalyticsAsyncLROPollingMethod(AsyncLROBasePolling): | ||
|
||
def finished(self): | ||
"""Is this polling finished? | ||
:rtype: bool | ||
""" | ||
return TextAnalyticsAsyncLROPollingMethod._finished(self.status()) | ||
|
||
@staticmethod | ||
def _finished(status): | ||
if hasattr(status, "value"): | ||
status = status.value | ||
return str(status).lower() in _FINISHED | ||
|
||
@staticmethod | ||
def _failed(status): | ||
if hasattr(status, "value"): | ||
status = status.value | ||
return str(status).lower() in _FAILED | ||
|
||
@staticmethod | ||
def _raise_if_bad_http_status_and_method(response): | ||
"""Check response status code is valid. | ||
Must be 200, 201, 202, or 204. | ||
:raises: BadStatus if invalid status. | ||
""" | ||
code = response.status_code | ||
if code in {200, 201, 202, 204}: | ||
return | ||
raise BadStatus( | ||
"Invalid return status {!r} for {!r} operation".format( | ||
code, response.request.method | ||
) | ||
) | ||
|
||
async def _poll(self): # pylint:disable=invalid-overridden-method | ||
"""Poll status of operation so long as operation is incomplete and | ||
we have an endpoint to query. | ||
:param callable update_cmd: The function to call to retrieve the | ||
latest status of the long running operation. | ||
:raises: OperationFailed if operation status 'Failed' or 'Canceled'. | ||
:raises: BadStatus if response status invalid. | ||
:raises: BadResponse if response invalid. | ||
""" | ||
while not self.finished(): | ||
await self._delay() | ||
await self.update_status() | ||
|
||
if TextAnalyticsAsyncLROPollingMethod._failed(self.status()): | ||
raise OperationFailed("Operation failed or canceled") | ||
|
||
final_get_url = self._operation.get_final_get_url(self._pipeline_response) | ||
if final_get_url: | ||
self._pipeline_response = await self.request_status(final_get_url) | ||
TextAnalyticsAsyncLROPollingMethod._raise_if_bad_http_status_and_method( | ||
self._pipeline_response.http_response | ||
) |
20 changes: 20 additions & 0 deletions
20
sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_async_paging.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# coding=utf-8 | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
from azure.core.async_paging import AsyncItemPaged | ||
|
||
|
||
class AnalyzeHealthcareResultAsync(AsyncItemPaged): | ||
def __init__(self, *args, **kwargs): | ||
self.model_version = kwargs.pop('model_version') | ||
self.statistics = kwargs.pop('statistics') | ||
super(AnalyzeHealthcareResultAsync, self).__init__(*args, **kwargs) | ||
|
||
|
||
class AnalyzeResultAsync(AsyncItemPaged): | ||
def __init__(self, *args, **kwargs): | ||
self.statistics = kwargs.pop('statistics') | ||
super(AnalyzeResultAsync, self).__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.