From b66fcc428a36c7d561e888fd365d0331fa6226c7 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 5 Oct 2020 14:49:27 -0400 Subject: [PATCH 1/2] removed error_map wrapping --- .../formrecognizer/_form_recognizer_client.py | 8 +------ .../formrecognizer/_form_training_client.py | 21 +++++-------------- .../azure/ai/formrecognizer/_helpers.py | 12 ----------- .../aio/_form_recognizer_client_async.py | 8 +------ .../aio/_form_training_client_async.py | 19 +++-------------- 5 files changed, 10 insertions(+), 58 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py index a7afa722a445..e89c8568d77e 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py @@ -21,7 +21,7 @@ prepare_content_result, prepare_form_result ) -from ._helpers import get_content_type, error_map +from ._helpers import get_content_type from ._form_base_client import FormRecognizerClientBase from ._polling import AnalyzePolling if TYPE_CHECKING: @@ -124,7 +124,6 @@ def begin_recognize_receipts(self, receipt, **kwargs): include_text_details=include_field_elements, cls=cls, polling=polling, - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -173,7 +172,6 @@ def begin_recognize_receipts_from_url(self, receipt_url, **kwargs): include_text_details=include_field_elements, cls=cls, polling=polling, - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -227,7 +225,6 @@ def begin_recognize_content(self, form, **kwargs): content_type=content_type, cls=kwargs.pop("cls", self._content_callback), polling=LROBasePolling(timeout=polling_interval, **kwargs), - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -256,7 +253,6 @@ def begin_recognize_content_from_url(self, form_url, **kwargs): file_stream={"source": form_url}, cls=kwargs.pop("cls", self._content_callback), polling=LROBasePolling(timeout=polling_interval, **kwargs), - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -322,7 +318,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume content_type=content_type, cls=deserialization_callback, polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[AnalyzePolling()], **kwargs), - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -367,7 +362,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume include_text_details=include_field_elements, cls=deserialization_callback, polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[AnalyzePolling()], **kwargs), - error_map=error_map, continuation_token=continuation_token, **kwargs ) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py index ee1c19309537..09d07c7e81c7 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py @@ -23,10 +23,8 @@ CopyRequest, CopyAuthorizationResult ) -from ._helpers import ( - error_map, - TransportWrapper -) +from ._helpers import TransportWrapper + from ._models import ( CustomFormModelInfo, AccountProperties, @@ -152,7 +150,6 @@ def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument ) ), cls=lambda pipeline_response, _, response_headers: pipeline_response, - error_map=error_map, **kwargs ) # type: PipelineResponseType @@ -176,7 +173,6 @@ def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument cls=deserialization_callback, continuation_token=continuation_token, polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[TrainingPolling()], **kwargs), - error_map=error_map, **kwargs ) @@ -204,11 +200,7 @@ def delete_model(self, model_id, **kwargs): if not model_id: raise ValueError("model_id cannot be None or empty.") - self._client.delete_custom_model( - model_id=model_id, - error_map=error_map, - **kwargs - ) + self._client.delete_custom_model(model_id=model_id, **kwargs) @distributed_trace def list_custom_models(self, **kwargs): @@ -231,7 +223,6 @@ def list_custom_models(self, **kwargs): """ return self._client.list_custom_models( # type: ignore cls=kwargs.pop("cls", lambda objs: [CustomFormModelInfo._from_generated(x) for x in objs]), - error_map=error_map, **kwargs ) @@ -254,7 +245,7 @@ def get_account_properties(self, **kwargs): :dedent: 8 :caption: Get properties for the form recognizer account. """ - response = self._client.get_custom_models(error_map=error_map, **kwargs) + response = self._client.get_custom_models(**kwargs) return AccountProperties._from_generated(response.summary) @distributed_trace @@ -281,7 +272,7 @@ def get_custom_model(self, model_id, **kwargs): if not model_id: raise ValueError("model_id cannot be None or empty.") - response = self._client.get_custom_model(model_id=model_id, include_keys=True, error_map=error_map, **kwargs) + response = self._client.get_custom_model(model_id=model_id, include_keys=True, **kwargs) return CustomFormModel._from_generated(response) @distributed_trace @@ -314,7 +305,6 @@ def get_copy_authorization(self, resource_id, resource_region, **kwargs): response = self._client.generate_model_copy_authorization( # type: ignore cls=lambda pipeline_response, deserialized, response_headers: pipeline_response, - error_map=error_map, **kwargs ) # type: PipelineResponse target = json.loads(response.http_response.text()) @@ -380,7 +370,6 @@ def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument ), cls=kwargs.pop("cls", _copy_callback), polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[CopyPolling()], **kwargs), - error_map=error_map, continuation_token=continuation_token, **kwargs ) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_helpers.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_helpers.py index 8dc558b46ec8..4a2236d3a5fd 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_helpers.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_helpers.py @@ -9,22 +9,10 @@ from azure.core.credentials import AzureKeyCredential from azure.core.pipeline.policies import AzureKeyCredentialPolicy from azure.core.pipeline.transport import HttpTransport -from azure.core.exceptions import ( - ResourceNotFoundError, - ResourceExistsError, - ClientAuthenticationError -) POLLING_INTERVAL = 5 COGNITIVE_KEY_HEADER = "Ocp-Apim-Subscription-Key" - -error_map = { - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 401: ClientAuthenticationError -} - def _get_deserialize(): from ._generated.v2_1_preview_1 import FormRecognizerClient return FormRecognizerClient("dummy", "dummy")._deserialize # pylint: disable=protected-access diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py index a5a32f5a9f8d..fb5b745efcad 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py @@ -20,7 +20,7 @@ prepare_content_result, prepare_form_result ) -from .._helpers import get_content_type, error_map +from .._helpers import get_content_type from .._polling import AnalyzePolling from ._form_base_client_async import FormRecognizerClientBaseAsync from .._models import FormPage, RecognizedForm @@ -129,7 +129,6 @@ async def begin_recognize_receipts( include_text_details=include_field_elements, cls=cls, polling=polling, - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -186,7 +185,6 @@ async def begin_recognize_receipts_from_url( include_text_details=include_field_elements, cls=cls, polling=polling, - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -246,7 +244,6 @@ async def begin_recognize_content( timeout=polling_interval, **kwargs ), - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -276,7 +273,6 @@ async def begin_recognize_content_from_url(self, form_url: str, **kwargs: Any) - timeout=polling_interval, **kwargs ), - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -351,7 +347,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume lro_algorithms=[AnalyzePolling()], **kwargs ), - error_map=error_map, continuation_token=continuation_token, **kwargs ) @@ -404,7 +399,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume lro_algorithms=[AnalyzePolling()], **kwargs ), - error_map=error_map, continuation_token=continuation_token, **kwargs ) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py index cf4dd9e81028..806c99ba0209 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py @@ -27,7 +27,6 @@ CopyRequest, CopyAuthorizationResult ) -from .._helpers import error_map from .._models import ( CustomFormModelInfo, AccountProperties, @@ -154,7 +153,6 @@ def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument ) ), cls=lambda pipeline_response, _, response_headers: pipeline_response, - error_map=error_map, **kwargs ) @@ -182,7 +180,6 @@ def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument cls=deserialization_callback, continuation_token=continuation_token, polling=AsyncLROBasePolling(timeout=polling_interval, lro_algorithms=[TrainingPolling()], **kwargs), - error_map=error_map, **kwargs ) @@ -209,11 +206,7 @@ async def delete_model(self, model_id: str, **kwargs: Any) -> None: if not model_id: raise ValueError("model_id cannot be None or empty.") - return await self._client.delete_custom_model( - model_id=model_id, - error_map=error_map, - **kwargs - ) + return await self._client.delete_custom_model(model_id=model_id, **kwargs) @distributed_trace def list_custom_models(self, **kwargs: Any) -> AsyncItemPaged[CustomFormModelInfo]: @@ -235,7 +228,6 @@ def list_custom_models(self, **kwargs: Any) -> AsyncItemPaged[CustomFormModelInf """ return self._client.list_custom_models( # type: ignore cls=kwargs.pop("cls", lambda objs: [CustomFormModelInfo._from_generated(x) for x in objs]), - error_map=error_map, **kwargs ) @@ -257,7 +249,7 @@ async def get_account_properties(self, **kwargs: Any) -> AccountProperties: :dedent: 8 :caption: Get properties for the form recognizer account. """ - response = await self._client.get_custom_models(error_map=error_map, **kwargs) + response = await self._client.get_custom_models(**kwargs) return AccountProperties._from_generated(response.summary) @distributed_trace_async @@ -284,10 +276,7 @@ async def get_custom_model(self, model_id: str, **kwargs: Any) -> CustomFormMode raise ValueError("model_id cannot be None or empty.") response = await self._client.get_custom_model( - model_id=model_id, - include_keys=True, - error_map=error_map, - **kwargs + model_id=model_id, include_keys=True, **kwargs ) return CustomFormModel._from_generated(response) @@ -325,7 +314,6 @@ async def get_copy_authorization( response = await self._client.generate_model_copy_authorization( # type: ignore cls=lambda pipeline_response, deserialized, response_headers: pipeline_response, - error_map=error_map, **kwargs ) # type: PipelineResponse target = json.loads(response.http_response.text()) @@ -394,7 +382,6 @@ def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument lro_algorithms=[CopyPolling()], **kwargs ), - error_map=error_map, continuation_token=continuation_token, **kwargs ) From 52e61d9eb3df84c6c5b34e407554f7afc46e72d6 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 5 Oct 2020 15:31:25 -0400 Subject: [PATCH 2/2] remove unnecessary param popping / code --- .../formrecognizer/_form_recognizer_client.py | 41 ++++---------- .../formrecognizer/_form_training_client.py | 3 - .../aio/_form_recognizer_client_async.py | 55 ++++--------------- .../aio/_form_training_client_async.py | 3 - 4 files changed, 20 insertions(+), 82 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py index e89c8568d77e..551b19709ee3 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py @@ -14,8 +14,8 @@ TYPE_CHECKING ) from azure.core.tracing.decorator import distributed_trace -from azure.core.polling import LROPoller from azure.core.polling.base_polling import LROBasePolling + from ._response_handlers import ( prepare_receipt, prepare_content_result, @@ -25,6 +25,7 @@ from ._form_base_client import FormRecognizerClientBase from ._polling import AnalyzePolling if TYPE_CHECKING: + from azure.core.polling import LROPoller from ._models import FormPage, RecognizedForm @@ -104,14 +105,11 @@ def begin_recognize_receipts(self, receipt, **kwargs): :caption: Recognize US sales receipt fields. """ locale = kwargs.pop("locale", None) - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) content_type = kwargs.pop("content_type", None) include_field_elements = kwargs.pop("include_field_elements", False) if content_type == "application/json": raise TypeError("Call begin_recognize_receipts_from_url() to analyze a receipt from a URL.") cls = kwargs.pop("cls", self._receipt_callback) - polling = LROBasePolling(timeout=polling_interval, **kwargs) if content_type is None: content_type = get_content_type(receipt) @@ -123,8 +121,7 @@ def begin_recognize_receipts(self, receipt, **kwargs): content_type=content_type, include_text_details=include_field_elements, cls=cls, - polling=polling, - continuation_token=continuation_token, + polling=True, **kwargs ) @@ -160,19 +157,15 @@ def begin_recognize_receipts_from_url(self, receipt_url, **kwargs): :caption: Recognize US sales receipt fields from a URL. """ locale = kwargs.pop("locale", None) - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) include_field_elements = kwargs.pop("include_field_elements", False) cls = kwargs.pop("cls", self._receipt_callback) - polling = LROBasePolling(timeout=polling_interval, **kwargs) if self.api_version == "2.1-preview.1" and locale: kwargs.update({"locale": locale}) return self._client.begin_analyze_receipt_async( # type: ignore file_stream={"source": receipt_url}, include_text_details=include_field_elements, cls=cls, - polling=polling, - continuation_token=continuation_token, + polling=True, **kwargs ) @@ -210,9 +203,6 @@ def begin_recognize_content(self, form, **kwargs): :dedent: 8 :caption: Recognize text and content/layout information from a form. """ - - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) content_type = kwargs.pop("content_type", None) if content_type == "application/json": raise TypeError("Call begin_recognize_content_from_url() to analyze a document from a URL.") @@ -224,8 +214,7 @@ def begin_recognize_content(self, form, **kwargs): file_stream=form, content_type=content_type, cls=kwargs.pop("cls", self._content_callback), - polling=LROBasePolling(timeout=polling_interval, **kwargs), - continuation_token=continuation_token, + polling=True, **kwargs ) @@ -246,14 +235,10 @@ def begin_recognize_content_from_url(self, form_url, **kwargs): :raises ~azure.core.exceptions.HttpResponseError: """ - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) - return self._client.begin_analyze_layout_async( # type: ignore file_stream={"source": form_url}, cls=kwargs.pop("cls", self._content_callback), - polling=LROBasePolling(timeout=polling_interval, **kwargs), - continuation_token=continuation_token, + polling=True, **kwargs ) @@ -295,9 +280,8 @@ def begin_recognize_custom_forms(self, model_id, form, **kwargs): if not model_id: raise ValueError("model_id cannot be None or empty.") - cls = kwargs.pop("cls", None) polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) + content_type = kwargs.pop("content_type", None) if content_type == "application/json": raise TypeError("Call begin_recognize_custom_forms_from_url() to analyze a document from a URL.") @@ -310,15 +294,13 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume analyze_result = self._deserialize(self._generated_models.AnalyzeOperationResult, raw_response) return prepare_form_result(analyze_result, model_id) - deserialization_callback = cls if cls else analyze_callback return self._client.begin_analyze_with_custom_model( # type: ignore file_stream=form, model_id=model_id, include_text_details=include_field_elements, content_type=content_type, - cls=deserialization_callback, + cls=kwargs.pop("cls", analyze_callback), polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[AnalyzePolling()], **kwargs), - continuation_token=continuation_token, **kwargs ) @@ -346,23 +328,20 @@ def begin_recognize_custom_forms_from_url(self, model_id, form_url, **kwargs): if not model_id: raise ValueError("model_id cannot be None or empty.") - cls = kwargs.pop("cls", None) polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) + include_field_elements = kwargs.pop("include_field_elements", False) def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argument analyze_result = self._deserialize(self._generated_models.AnalyzeOperationResult, raw_response) return prepare_form_result(analyze_result, model_id) - deserialization_callback = cls if cls else analyze_callback return self._client.begin_analyze_with_custom_model( # type: ignore file_stream={"source": form_url}, model_id=model_id, include_text_details=include_field_elements, - cls=deserialization_callback, + cls=kwargs.pop("cls", analyze_callback), polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[AnalyzePolling()], **kwargs), - continuation_token=continuation_token, **kwargs ) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py index 09d07c7e81c7..ae1dd6b7fe0f 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py @@ -349,9 +349,7 @@ def begin_copy_model( if not model_id: raise ValueError("model_id cannot be None or empty.") - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument copy_result = self._deserialize(self._generated_models.CopyOperationResult, raw_response) @@ -370,7 +368,6 @@ def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument ), cls=kwargs.pop("cls", _copy_callback), polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[CopyPolling()], **kwargs), - continuation_token=continuation_token, **kwargs ) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py index fb5b745efcad..da355cb0e88d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py @@ -105,18 +105,11 @@ async def begin_recognize_receipts( :caption: Recognize US sales receipt fields. """ locale = kwargs.pop("locale", None) - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) content_type = kwargs.pop("content_type", None) if content_type == "application/json": raise TypeError("Call begin_recognize_receipts_from_url() to analyze a receipt from a URL.") include_field_elements = kwargs.pop("include_field_elements", False) - cls = kwargs.pop("cls", self._receipt_callback) - polling = AsyncLROBasePolling( - timeout=polling_interval, - **kwargs - ) if content_type is None: content_type = get_content_type(receipt) @@ -127,9 +120,8 @@ async def begin_recognize_receipts( file_stream=receipt, content_type=content_type, include_text_details=include_field_elements, - cls=cls, - polling=polling, - continuation_token=continuation_token, + cls=kwargs.pop("cls", self._receipt_callback), + polling=True, **kwargs ) @@ -168,14 +160,8 @@ async def begin_recognize_receipts_from_url( :caption: Recognize US sales receipt fields from a URL. """ locale = kwargs.pop("locale", None) - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) + include_field_elements = kwargs.pop("include_field_elements", False) - cls = kwargs.pop("cls", self._receipt_callback) - polling = AsyncLROBasePolling( - timeout=polling_interval, - **kwargs - ) if self.api_version == "2.1-preview.1" and locale: kwargs.update({"locale": locale}) @@ -183,9 +169,8 @@ async def begin_recognize_receipts_from_url( return await self._client.begin_analyze_receipt_async( # type: ignore file_stream={"source": receipt_url}, include_text_details=include_field_elements, - cls=cls, - polling=polling, - continuation_token=continuation_token, + cls=kwargs.pop("cls", self._receipt_callback), + polling=True, **kwargs ) @@ -227,8 +212,6 @@ async def begin_recognize_content( :caption: Recognize text and content/layout information from a form. """ - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) content_type = kwargs.pop("content_type", None) if content_type == "application/json": raise TypeError("Call begin_recognize_content_from_url() to analyze a document from a URL.") @@ -240,11 +223,7 @@ async def begin_recognize_content( file_stream=form, content_type=content_type, cls=kwargs.pop("cls", self._content_callback), - polling=AsyncLROBasePolling( - timeout=polling_interval, - **kwargs - ), - continuation_token=continuation_token, + polling=True, **kwargs ) @@ -264,16 +243,10 @@ async def begin_recognize_content_from_url(self, form_url: str, **kwargs: Any) - :raises ~azure.core.exceptions.HttpResponseError: """ - polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) return await self._client.begin_analyze_layout_async( # type: ignore file_stream={"source": form_url}, cls=kwargs.pop("cls", self._content_callback), - polling=AsyncLROBasePolling( - timeout=polling_interval, - **kwargs - ), - continuation_token=continuation_token, + polling=True, **kwargs ) @@ -319,9 +292,7 @@ async def begin_recognize_custom_forms( if not model_id: raise ValueError("model_id cannot be None or empty.") - cls = kwargs.pop("cls", None) polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) content_type = kwargs.pop("content_type", None) if content_type == "application/json": raise TypeError("Call begin_recognize_custom_forms_from_url() to analyze a document from a URL.") @@ -335,19 +306,17 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume analyze_result = self._deserialize(self._generated_models.AnalyzeOperationResult, raw_response) return prepare_form_result(analyze_result, model_id) - deserialization_callback = cls if cls else analyze_callback return await self._client.begin_analyze_with_custom_model( # type: ignore file_stream=form, model_id=model_id, include_text_details=include_field_elements, content_type=content_type, - cls=deserialization_callback, + cls=kwargs.pop("cls", analyze_callback), polling=AsyncLROBasePolling( timeout=polling_interval, lro_algorithms=[AnalyzePolling()], **kwargs ), - continuation_token=continuation_token, **kwargs ) @@ -378,28 +347,24 @@ async def begin_recognize_custom_forms_from_url( if not model_id: raise ValueError("model_id cannot be None or empty.") - - cls = kwargs.pop("cls", None) polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - continuation_token = kwargs.pop("continuation_token", None) + include_field_elements = kwargs.pop("include_field_elements", False) def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argument analyze_result = self._deserialize(self._generated_models.AnalyzeOperationResult, raw_response) return prepare_form_result(analyze_result, model_id) - deserialization_callback = cls if cls else analyze_callback return await self._client.begin_analyze_with_custom_model( # type: ignore file_stream={"source": form_url}, model_id=model_id, include_text_details=include_field_elements, - cls=deserialization_callback, + cls=kwargs.pop("cls", analyze_callback), polling=AsyncLROBasePolling( timeout=polling_interval, lro_algorithms=[AnalyzePolling()], **kwargs ), - continuation_token=continuation_token, **kwargs ) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py index 806c99ba0209..43ffeb3f8f8e 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py @@ -357,8 +357,6 @@ async def begin_copy_model( if not model_id: raise ValueError("model_id cannot be None or empty.") - - continuation_token = kwargs.pop("continuation_token", None) polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument @@ -382,7 +380,6 @@ def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument lro_algorithms=[CopyPolling()], **kwargs ), - continuation_token=continuation_token, **kwargs )