From 775200d487e573797e76fe2f6c08a598bce5a4d3 Mon Sep 17 00:00:00 2001 From: Changlong Liu Date: Thu, 5 May 2022 14:09:30 +0800 Subject: [PATCH 1/3] import-azure-core --- README.rst | 8 ++++++++ msrest/exceptions.py | 12 +----------- msrest/version.py | 2 +- setup.py | 3 ++- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index 300d328ced..94ad726895 100644 --- a/README.rst +++ b/README.rst @@ -20,6 +20,14 @@ To install: Release History --------------- +2022-05-05 Version 0.7.0 ++++++++++++++++++++++++++ + +**Features** + +- Add `azure-core` as installation requirement #247 +- Replace `SerializationError` and `DeserializationError` in `msrest.exceptions` with those in `azure.core` #247 + 2021-01-26 Version 0.6.21 +++++++++++++++++++++++++ diff --git a/msrest/exceptions.py b/msrest/exceptions.py index b274e953d1..7d6d8dcf73 100644 --- a/msrest/exceptions.py +++ b/msrest/exceptions.py @@ -28,7 +28,7 @@ import sys from typing import Callable, Any, Optional, TYPE_CHECKING - +from azure.core.exceptions import SerializationError, DeserializationError _LOGGER = logging.getLogger(__name__) @@ -68,16 +68,6 @@ def __init__(self, message, inner_exception=None, *args, **kwargs): super(ClientException, self).__init__(message, *args, **kwargs) # type: ignore -class SerializationError(ClientException): - """Error raised during request serialization.""" - pass - - -class DeserializationError(ClientException): - """Error raised during response deserialization.""" - pass - - class TokenExpiredError(ClientException): """OAuth token expired, request failed.""" pass diff --git a/msrest/version.py b/msrest/version.py index e24924ac7f..eea1f70de6 100644 --- a/msrest/version.py +++ b/msrest/version.py @@ -25,4 +25,4 @@ # -------------------------------------------------------------------------- #: version of this package. Use msrest.__version__ instead -msrest_version = "0.6.21" +msrest_version = "0.7.0" diff --git a/setup.py b/setup.py index 27c113299f..c8590e9f95 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setup( name='msrest', - version='0.6.21', + version='0.7.0', author='Microsoft Corporation', packages=find_packages(exclude=["tests", "tests.*"]), url=("https://github.com/Azure/msrest-for-python"), @@ -53,6 +53,7 @@ "requests_oauthlib>=0.5.0", "isodate>=0.6.0", "certifi>=2017.4.17", + "azure-core>=1.24.0", ], include_package_data=True, package_data={ From e84582e60ed9bdeb03b40b39c4e9b5509f54f9d2 Mon Sep 17 00:00:00 2001 From: Changlong Liu Date: Fri, 6 May 2022 09:26:32 +0800 Subject: [PATCH 2/3] fix-test --- .travis.yml | 20 ++++++++++++++++++++ dev_requirements.txt | 3 ++- msrest/serialization.py | 14 +++++++++++--- msrest/universal_http/async_requests.py | 4 ++-- tests/test_serialization.py | 7 +++++++ 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8233f48c20..6d0e773135 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,14 @@ jobs: python: 3.8 env: TOXENV=py38 <<: *_test + - stage: Test + python: 3.9 + env: TOXENV=py39 + <<: *_test + - stage: Test + python: 3.10 + env: TOXENV=py310 + <<: *_test - stage: Test python: 2.7 env: TOXENV=py27-autorest @@ -69,6 +77,16 @@ jobs: env: TOXENV=py38-autorest <<: *_autorest_install <<: *_test + - stage: Test + python: 3.9 + env: TOXENV=py39-autorest + <<: *_autorest_install + <<: *_test + - stage: Test + python: 3.10 + env: TOXENV=py310-autorest + <<: *_autorest_install + <<: *_test allow_failures: - env: TOXENV=py27-autorest @@ -76,6 +94,8 @@ jobs: - env: TOXENV=py36-autorest - env: TOXENV=py37-autorest - env: TOXENV=py38-autorest + - env: TOXENV=py39-autorest + - env: TOXENV=py310-autorest deploy: provider: pypi user: Laurent.Mazuel diff --git a/dev_requirements.txt b/dev_requirements.txt index eb4dde0361..f032fbbdcb 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -11,4 +11,5 @@ pylint aiohttp;python_full_version>="3.5.2" # async in msrest was experimental, we won't update trio==0.14.0;python_version == '3.5' -trio==0.16.0;python_version >= '3.6' +trio==0.16.0;python_version >= '3.6' and python_version < '3.10' +trio==0.20.0;python_version >= '3.10' diff --git a/msrest/serialization.py b/msrest/serialization.py index f8503e6e54..64cb2b78cd 100644 --- a/msrest/serialization.py +++ b/msrest/serialization.py @@ -569,7 +569,9 @@ def _serialize(self, target_obj, data_type=None, **kwargs): _serialized.update(_new_attr) _new_attr = _new_attr[k] _serialized = _serialized[k] - except ValueError: + except ValueError as err: + if isinstance(err, SerializationError): + raise err continue except (AttributeError, KeyError, TypeError) as err: @@ -776,6 +778,8 @@ def serialize_data(self, data, data_type, **kwargs): data, data_type[1:-1], **kwargs) except (ValueError, TypeError) as err: + if (isinstance(err, SerializationError)): + raise err # don't rewrap as SerializationError msg = "Unable to serialize value: {!r} as type: {!r}." raise_with_traceback( SerializationError, msg.format(data, data_type), err) @@ -858,7 +862,9 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs): for d in data: try: serialized.append(self.serialize_data(d, iter_type, **kwargs)) - except ValueError: + except ValueError as err: + if isinstance(err, SerializationError): + raise err serialized.append(None) if div: @@ -914,7 +920,9 @@ def serialize_dict(self, attr, dict_type, **kwargs): try: serialized[self.serialize_unicode(key)] = self.serialize_data( value, dict_type, **kwargs) - except ValueError: + except ValueError as err: + if isinstance(err, SerializationError): + raise err serialized[self.serialize_unicode(key)] = None if 'xml' in serialization_ctxt: diff --git a/msrest/universal_http/async_requests.py b/msrest/universal_http/async_requests.py index 7bdaf8ff94..40a3a352ee 100644 --- a/msrest/universal_http/async_requests.py +++ b/msrest/universal_http/async_requests.py @@ -161,7 +161,7 @@ def __init__(self, response: requests.Response, user_callback: Optional[Callable async def __anext__(self): try: - chunk = await trio.run_sync_in_worker_thread( + chunk = await trio.to_thread.run_sync( _msrest_next, self.iter_content_func, ) @@ -209,7 +209,7 @@ async def send(self, request: ClientRequest, **kwargs: Any) -> AsyncClientRespon session = kwargs.pop('session', self.session) trio_limiter = kwargs.get("trio_limiter", None) - future = trio.run_sync_in_worker_thread( + future = trio.to_thread.run_sync( functools.partial( session.request, request.method, diff --git a/tests/test_serialization.py b/tests/test_serialization.py index f8e0144c8b..9c97550d01 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -42,6 +42,7 @@ from msrest.serialization import Model, last_restapi_key_transformer, full_restapi_key_transformer, rest_key_extractor from msrest import Serializer, Deserializer from msrest.exceptions import SerializationError, DeserializationError, ValidationError +from azure.core.exceptions import SerializationError as AzureCoreSerializationError, DeserializationError as AzureCoreDeserializationError from . import storage_models @@ -2579,5 +2580,11 @@ def __init__(self, name=None): self.assertTrue(animal1!=animal2) self.assertTrue(animal1==animal3) +class TestAzureCoreExceptions(unittest.TestCase): + + def test_azure_core_exceptions(self): + self.assertEqual(SerializationError, AzureCoreSerializationError) + self.assertEqual(DeserializationError, AzureCoreDeserializationError) + if __name__ == '__main__': unittest.main() From 909abb586934b0fa876f2ac04fc61b4385179269 Mon Sep 17 00:00:00 2001 From: Changlong Liu Date: Fri, 6 May 2022 09:41:10 +0800 Subject: [PATCH 3/3] revert-yml --- .travis.yml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6d0e773135..8233f48c20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,14 +44,6 @@ jobs: python: 3.8 env: TOXENV=py38 <<: *_test - - stage: Test - python: 3.9 - env: TOXENV=py39 - <<: *_test - - stage: Test - python: 3.10 - env: TOXENV=py310 - <<: *_test - stage: Test python: 2.7 env: TOXENV=py27-autorest @@ -77,16 +69,6 @@ jobs: env: TOXENV=py38-autorest <<: *_autorest_install <<: *_test - - stage: Test - python: 3.9 - env: TOXENV=py39-autorest - <<: *_autorest_install - <<: *_test - - stage: Test - python: 3.10 - env: TOXENV=py310-autorest - <<: *_autorest_install - <<: *_test allow_failures: - env: TOXENV=py27-autorest @@ -94,8 +76,6 @@ jobs: - env: TOXENV=py36-autorest - env: TOXENV=py37-autorest - env: TOXENV=py38-autorest - - env: TOXENV=py39-autorest - - env: TOXENV=py310-autorest deploy: provider: pypi user: Laurent.Mazuel