Skip to content

Commit

Permalink
import-azure-core (#247)
Browse files Browse the repository at this point in the history
* import-azure-core

* fix-test

* revert-yml
  • Loading branch information
changlong-liu committed May 18, 2022
1 parent f5b857b commit c97db9d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 19 deletions.
8 changes: 8 additions & 0 deletions README.rst
Expand Up @@ -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
+++++++++++++++++++++++++

Expand Down
3 changes: 2 additions & 1 deletion dev_requirements.txt
Expand Up @@ -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'
12 changes: 1 addition & 11 deletions msrest/exceptions.py
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions msrest/serialization.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions msrest/universal_http/async_requests.py
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion msrest/version.py
Expand Up @@ -25,4 +25,4 @@
# --------------------------------------------------------------------------

#: version of this package. Use msrest.__version__ instead
msrest_version = "0.6.21"
msrest_version = "0.7.0"
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -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"),
Expand All @@ -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={
Expand Down
7 changes: 7 additions & 0 deletions tests/test_serialization.py
Expand Up @@ -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

Expand Down Expand Up @@ -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()

0 comments on commit c97db9d

Please sign in to comment.