@autorest/python 6.2.15 → 6.2.16
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.
|
@@ -21,6 +21,7 @@ import isodate
|
|
|
21
21
|
from azure.core.exceptions import DeserializationError
|
|
22
22
|
from azure.core import CaseInsensitiveEnumMeta
|
|
23
23
|
from azure.core.pipeline import PipelineResponse
|
|
24
|
+
from azure.core.serialization import NULL as AzureCoreNull
|
|
24
25
|
|
|
25
26
|
_LOGGER = logging.getLogger(__name__)
|
|
26
27
|
|
|
@@ -157,6 +158,8 @@ class AzureJSONEncoder(JSONEncoder):
|
|
|
157
158
|
return {k: v for k, v in o.items() if k not in readonly_props}
|
|
158
159
|
if isinstance(o, (bytes, bytearray)):
|
|
159
160
|
return base64.b64encode(o).decode()
|
|
161
|
+
if o is AzureCoreNull:
|
|
162
|
+
return None
|
|
160
163
|
try:
|
|
161
164
|
return super(AzureJSONEncoder, self).default(o)
|
|
162
165
|
except TypeError:
|
|
@@ -263,7 +266,8 @@ def _get_model(module_name: str, model_name: str):
|
|
|
263
266
|
module_end = module_name.rsplit(".", 1)[0]
|
|
264
267
|
module = sys.modules[module_end]
|
|
265
268
|
models.update({k: v for k, v in module.__dict__.items() if isinstance(v, type)})
|
|
266
|
-
model_name
|
|
269
|
+
if isinstance(model_name, str):
|
|
270
|
+
model_name = model_name.split(".")[-1]
|
|
267
271
|
if model_name not in models:
|
|
268
272
|
return model_name
|
|
269
273
|
return models[model_name]
|
|
@@ -465,13 +469,15 @@ class Model(_MyMutableMapping):
|
|
|
465
469
|
|
|
466
470
|
|
|
467
471
|
def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-return-statements, too-many-statements
|
|
468
|
-
annotation: typing.Any, module: typing.Optional[str],
|
|
472
|
+
annotation: typing.Any, module: typing.Optional[str], rf: "_RestField" = None
|
|
469
473
|
) -> typing.Optional[typing.Callable[[typing.Any], typing.Any]]:
|
|
470
474
|
if not annotation or annotation in [int, float]:
|
|
471
475
|
return None
|
|
472
476
|
|
|
473
477
|
try:
|
|
474
478
|
if module and _is_model(_get_model(module, annotation)):
|
|
479
|
+
if rf:
|
|
480
|
+
rf._is_model = True
|
|
475
481
|
def _deserialize_model(model_deserializer: typing.Optional[typing.Callable], obj):
|
|
476
482
|
if _is_model(obj):
|
|
477
483
|
return obj
|
|
@@ -510,7 +516,7 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
|
|
|
510
516
|
if any(a for a in annotation.__args__ if a == type(None)):
|
|
511
517
|
|
|
512
518
|
if_obj_deserializer = _get_deserialize_callable_from_annotation(
|
|
513
|
-
next(a for a in annotation.__args__ if a != type(None)), module
|
|
519
|
+
next(a for a in annotation.__args__ if a != type(None)), module, rf
|
|
514
520
|
)
|
|
515
521
|
|
|
516
522
|
def _deserialize_with_optional(if_obj_deserializer: typing.Optional[typing.Callable], obj):
|
|
@@ -533,8 +539,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
|
|
|
533
539
|
|
|
534
540
|
try:
|
|
535
541
|
if annotation._name == "Dict":
|
|
536
|
-
key_deserializer = _get_deserialize_callable_from_annotation(annotation.__args__[0], module)
|
|
537
|
-
value_deserializer = _get_deserialize_callable_from_annotation(annotation.__args__[1], module)
|
|
542
|
+
key_deserializer = _get_deserialize_callable_from_annotation(annotation.__args__[0], module, rf)
|
|
543
|
+
value_deserializer = _get_deserialize_callable_from_annotation(annotation.__args__[1], module, rf)
|
|
538
544
|
|
|
539
545
|
def _deserialize_dict(
|
|
540
546
|
key_deserializer: typing.Optional[typing.Callable],
|
|
@@ -568,10 +574,10 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
|
|
|
568
574
|
)
|
|
569
575
|
|
|
570
576
|
entry_deserializers = [
|
|
571
|
-
_get_deserialize_callable_from_annotation(dt, module) for dt in annotation.__args__
|
|
577
|
+
_get_deserialize_callable_from_annotation(dt, module, rf) for dt in annotation.__args__
|
|
572
578
|
]
|
|
573
579
|
return functools.partial(_deserialize_multiple_sequence, entry_deserializers)
|
|
574
|
-
deserializer = _get_deserialize_callable_from_annotation(annotation.__args__[0], module)
|
|
580
|
+
deserializer = _get_deserialize_callable_from_annotation(annotation.__args__[0], module, rf)
|
|
575
581
|
|
|
576
582
|
def _deserialize_sequence(
|
|
577
583
|
deserializer: typing.Optional[typing.Callable],
|
|
@@ -673,7 +679,7 @@ class _RestField:
|
|
|
673
679
|
def _get_deserialize_callable_from_annotation(
|
|
674
680
|
self, annotation: typing.Any
|
|
675
681
|
) -> typing.Optional[typing.Callable[[typing.Any], typing.Any]]:
|
|
676
|
-
return _get_deserialize_callable_from_annotation(annotation, self._module)
|
|
682
|
+
return _get_deserialize_callable_from_annotation(annotation, self._module, self)
|
|
677
683
|
|
|
678
684
|
|
|
679
685
|
def rest_field(
|
|
@@ -64,6 +64,7 @@ import xml.etree.ElementTree as ET
|
|
|
64
64
|
import isodate # type: ignore
|
|
65
65
|
|
|
66
66
|
from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback
|
|
67
|
+
from azure.core.serialization import NULL as AzureCoreNull
|
|
67
68
|
|
|
68
69
|
_BOM = codecs.BOM_UTF8.decode(encoding="utf-8")
|
|
69
70
|
|
|
@@ -804,6 +805,8 @@ class Serializer(object):
|
|
|
804
805
|
raise ValueError("No value for given attribute")
|
|
805
806
|
|
|
806
807
|
try:
|
|
808
|
+
if data is AzureCoreNull:
|
|
809
|
+
return None
|
|
807
810
|
if data_type in self.basic_types.values():
|
|
808
811
|
return self.serialize_basic(data, data_type, **kwargs)
|
|
809
812
|
|