diracx-client 0.0.1a44__py3-none-any.whl → 0.0.1a46__py3-none-any.whl
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.
- diracx/_client_importer.py +2 -2
- diracx/client/_generated/__init__.py +1 -1
- diracx/client/_generated/_client.py +11 -34
- diracx/client/_generated/_configuration.py +7 -19
- diracx/client/_generated/_utils/__init__.py +1 -1
- diracx/client/_generated/_utils/serialization.py +71 -225
- diracx/client/_generated/_utils/utils.py +4 -10
- diracx/client/_generated/aio/__init__.py +1 -1
- diracx/client/_generated/aio/_client.py +9 -30
- diracx/client/_generated/aio/_configuration.py +8 -22
- diracx/client/_generated/aio/_patch.py +1 -3
- diracx/client/_generated/aio/operations/__init__.py +1 -1
- diracx/client/_generated/aio/operations/_operations.py +239 -368
- diracx/client/_generated/models/__init__.py +2 -3
- diracx/client/_generated/models/_enums.py +1 -1
- diracx/client/_generated/models/_models.py +39 -91
- diracx/client/_generated/operations/__init__.py +1 -1
- diracx/client/_generated/operations/_operations.py +312 -499
- diracx/client/patches/client/common.py +1 -1
- diracx/client/patches/utils.py +1 -1
- {diracx_client-0.0.1a44.dist-info → diracx_client-0.0.1a46.dist-info}/METADATA +2 -1
- diracx_client-0.0.1a46.dist-info/RECORD +45 -0
- diracx_client-0.0.1a44.dist-info/RECORD +0 -45
- {diracx_client-0.0.1a44.dist-info → diracx_client-0.0.1a46.dist-info}/WHEEL +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
# pylint: disable=line-too-long,useless-suppression,too-many-lines
|
2
2
|
# coding=utf-8
|
3
3
|
# --------------------------------------------------------------------------
|
4
|
-
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.4, generator: @autorest/python@6.34.
|
4
|
+
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.4, generator: @autorest/python@6.34.2)
|
5
5
|
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
6
6
|
# --------------------------------------------------------------------------
|
7
7
|
|
@@ -58,9 +58,7 @@ class RawDeserializer:
|
|
58
58
|
CONTEXT_NAME = "deserialized_data"
|
59
59
|
|
60
60
|
@classmethod
|
61
|
-
def deserialize_from_text(
|
62
|
-
cls, data: Optional[Union[AnyStr, IO]], content_type: Optional[str] = None
|
63
|
-
) -> Any:
|
61
|
+
def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type: Optional[str] = None) -> Any:
|
64
62
|
"""Decode data according to content-type.
|
65
63
|
|
66
64
|
Accept a stream of data as well, but will be load at once in memory for now.
|
@@ -93,9 +91,7 @@ class RawDeserializer:
|
|
93
91
|
try:
|
94
92
|
return json.loads(data_as_str)
|
95
93
|
except ValueError as err:
|
96
|
-
raise DeserializationError(
|
97
|
-
"JSON is invalid: {}".format(err), err
|
98
|
-
) from err
|
94
|
+
raise DeserializationError("JSON is invalid: {}".format(err), err) from err
|
99
95
|
elif "xml" in (content_type or []):
|
100
96
|
try:
|
101
97
|
|
@@ -129,14 +125,10 @@ class RawDeserializer:
|
|
129
125
|
raise DeserializationError("XML is invalid") from err
|
130
126
|
elif content_type.startswith("text/"):
|
131
127
|
return data_as_str
|
132
|
-
raise DeserializationError(
|
133
|
-
"Cannot deserialize content-type: {}".format(content_type)
|
134
|
-
)
|
128
|
+
raise DeserializationError("Cannot deserialize content-type: {}".format(content_type))
|
135
129
|
|
136
130
|
@classmethod
|
137
|
-
def deserialize_from_http_generics(
|
138
|
-
cls, body_bytes: Optional[Union[AnyStr, IO]], headers: Mapping
|
139
|
-
) -> Any:
|
131
|
+
def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]], headers: Mapping) -> Any:
|
140
132
|
"""Deserialize from HTTP response.
|
141
133
|
|
142
134
|
Use bytes and headers to NOT use any requests/aiohttp or whatever
|
@@ -188,9 +180,7 @@ def attribute_transformer(key, attr_desc, value): # pylint: disable=unused-argu
|
|
188
180
|
return (key, value)
|
189
181
|
|
190
182
|
|
191
|
-
def full_restapi_key_transformer(
|
192
|
-
key, attr_desc, value
|
193
|
-
): # pylint: disable=unused-argument
|
183
|
+
def full_restapi_key_transformer(key, attr_desc, value): # pylint: disable=unused-argument
|
194
184
|
"""A key transformer that returns the full RestAPI key path.
|
195
185
|
|
196
186
|
:param str key: The attribute name
|
@@ -245,17 +235,9 @@ class Model:
|
|
245
235
|
self.additional_properties: Optional[Dict[str, Any]] = {}
|
246
236
|
for k in kwargs: # pylint: disable=consider-using-dict-items
|
247
237
|
if k not in self._attribute_map:
|
248
|
-
_LOGGER.warning(
|
249
|
-
"%s is not a known attribute of class %s and will be ignored",
|
250
|
-
k,
|
251
|
-
self.__class__,
|
252
|
-
)
|
238
|
+
_LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__)
|
253
239
|
elif k in self._validation and self._validation[k].get("readonly", False):
|
254
|
-
_LOGGER.warning(
|
255
|
-
"Readonly attribute %s will be ignored in class %s",
|
256
|
-
k,
|
257
|
-
self.__class__,
|
258
|
-
)
|
240
|
+
_LOGGER.warning("Readonly attribute %s will be ignored in class %s", k, self.__class__)
|
259
241
|
else:
|
260
242
|
setattr(self, k, kwargs[k])
|
261
243
|
|
@@ -306,11 +288,7 @@ class Model:
|
|
306
288
|
except AttributeError:
|
307
289
|
xml_map = {}
|
308
290
|
|
309
|
-
return _create_xml_node(
|
310
|
-
xml_map.get("name", cls.__name__),
|
311
|
-
xml_map.get("prefix", None),
|
312
|
-
xml_map.get("ns", None),
|
313
|
-
)
|
291
|
+
return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None))
|
314
292
|
|
315
293
|
def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
|
316
294
|
"""Return the JSON that would be sent to server from this model.
|
@@ -331,10 +309,8 @@ class Model:
|
|
331
309
|
def as_dict(
|
332
310
|
self,
|
333
311
|
keep_readonly: bool = True,
|
334
|
-
key_transformer: Callable[
|
335
|
-
|
336
|
-
] = attribute_transformer,
|
337
|
-
**kwargs: Any,
|
312
|
+
key_transformer: Callable[[str, Dict[str, Any], Any], Any] = attribute_transformer,
|
313
|
+
**kwargs: Any
|
338
314
|
) -> JSON:
|
339
315
|
"""Return a dict that can be serialized using json.dump.
|
340
316
|
|
@@ -377,9 +353,7 @@ class Model:
|
|
377
353
|
try:
|
378
354
|
str_models = cls.__module__.rsplit(".", 1)[0]
|
379
355
|
models = sys.modules[str_models]
|
380
|
-
client_models = {
|
381
|
-
k: v for k, v in models.__dict__.items() if isinstance(v, type)
|
382
|
-
}
|
356
|
+
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
|
383
357
|
if cls.__name__ not in client_models:
|
384
358
|
raise ValueError("Not Autorest generated code")
|
385
359
|
except Exception: # pylint: disable=broad-exception-caught
|
@@ -438,9 +412,7 @@ class Model:
|
|
438
412
|
return {}
|
439
413
|
result = dict(cls._subtype_map[key])
|
440
414
|
for valuetype in cls._subtype_map[key].values():
|
441
|
-
result.update(
|
442
|
-
objects[valuetype]._flatten_subtype(key, objects)
|
443
|
-
) # pylint: disable=protected-access
|
415
|
+
result.update(objects[valuetype]._flatten_subtype(key, objects)) # pylint: disable=protected-access
|
444
416
|
return result
|
445
417
|
|
446
418
|
@classmethod
|
@@ -458,13 +430,9 @@ class Model:
|
|
458
430
|
|
459
431
|
if not isinstance(response, ET.Element):
|
460
432
|
rest_api_response_key = cls._get_rest_key_parts(subtype_key)[-1]
|
461
|
-
subtype_value = response.get(
|
462
|
-
rest_api_response_key, None
|
463
|
-
) or response.get(subtype_key, None)
|
433
|
+
subtype_value = response.get(rest_api_response_key, None) or response.get(subtype_key, None)
|
464
434
|
else:
|
465
|
-
subtype_value = xml_key_extractor(
|
466
|
-
subtype_key, cls._attribute_map[subtype_key], response
|
467
|
-
)
|
435
|
+
subtype_value = xml_key_extractor(subtype_key, cls._attribute_map[subtype_key], response)
|
468
436
|
if subtype_value:
|
469
437
|
# Try to match base class. Can be class name only
|
470
438
|
# (bug to fix in Autorest to support x-ms-discriminator-name)
|
@@ -481,11 +449,7 @@ class Model:
|
|
481
449
|
)
|
482
450
|
break
|
483
451
|
else:
|
484
|
-
_LOGGER.warning(
|
485
|
-
"Discriminator %s is absent or null, use base class %s.",
|
486
|
-
subtype_key,
|
487
|
-
cls.__name__,
|
488
|
-
)
|
452
|
+
_LOGGER.warning("Discriminator %s is absent or null, use base class %s.", subtype_key, cls.__name__)
|
489
453
|
break
|
490
454
|
return cls
|
491
455
|
|
@@ -597,25 +561,18 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
597
561
|
try:
|
598
562
|
is_xml_model_serialization = kwargs["is_xml"]
|
599
563
|
except KeyError:
|
600
|
-
is_xml_model_serialization = kwargs.setdefault(
|
601
|
-
"is_xml", target_obj.is_xml_model()
|
602
|
-
)
|
564
|
+
is_xml_model_serialization = kwargs.setdefault("is_xml", target_obj.is_xml_model())
|
603
565
|
|
604
566
|
serialized = {}
|
605
567
|
if is_xml_model_serialization:
|
606
|
-
serialized = (
|
607
|
-
target_obj._create_xml_node()
|
608
|
-
) # pylint: disable=protected-access
|
568
|
+
serialized = target_obj._create_xml_node() # pylint: disable=protected-access
|
609
569
|
try:
|
610
570
|
attributes = target_obj._attribute_map # pylint: disable=protected-access
|
611
571
|
for attr, attr_desc in attributes.items():
|
612
572
|
attr_name = attr
|
613
|
-
if (
|
614
|
-
|
615
|
-
|
616
|
-
attr_name, {}
|
617
|
-
).get("readonly", False)
|
618
|
-
):
|
573
|
+
if not keep_readonly and target_obj._validation.get( # pylint: disable=protected-access
|
574
|
+
attr_name, {}
|
575
|
+
).get("readonly", False):
|
619
576
|
continue
|
620
577
|
|
621
578
|
if attr_name == "additional_properties" and attr_desc["key"] == "":
|
@@ -628,15 +585,11 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
628
585
|
if is_xml_model_serialization:
|
629
586
|
pass # Don't provide "transformer" for XML for now. Keep "orig_attr"
|
630
587
|
else: # JSON
|
631
|
-
keys, orig_attr = key_transformer(
|
632
|
-
attr, attr_desc.copy(), orig_attr
|
633
|
-
)
|
588
|
+
keys, orig_attr = key_transformer(attr, attr_desc.copy(), orig_attr)
|
634
589
|
keys = keys if isinstance(keys, list) else [keys]
|
635
590
|
|
636
591
|
kwargs["serialization_ctxt"] = attr_desc
|
637
|
-
new_attr = self.serialize_data(
|
638
|
-
orig_attr, attr_desc["type"], **kwargs
|
639
|
-
)
|
592
|
+
new_attr = self.serialize_data(orig_attr, attr_desc["type"], **kwargs)
|
640
593
|
|
641
594
|
if is_xml_model_serialization:
|
642
595
|
xml_desc = attr_desc.get("xml", {})
|
@@ -685,9 +638,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
685
638
|
raise
|
686
639
|
|
687
640
|
except (AttributeError, KeyError, TypeError) as err:
|
688
|
-
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(
|
689
|
-
attr_name, class_name, str(target_obj)
|
690
|
-
)
|
641
|
+
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
|
691
642
|
raise SerializationError(msg) from err
|
692
643
|
return serialized
|
693
644
|
|
@@ -709,9 +660,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
709
660
|
is_xml_model_serialization = kwargs["is_xml"]
|
710
661
|
except KeyError:
|
711
662
|
if internal_data_type and issubclass(internal_data_type, Model):
|
712
|
-
is_xml_model_serialization = kwargs.setdefault(
|
713
|
-
"is_xml", internal_data_type.is_xml_model()
|
714
|
-
)
|
663
|
+
is_xml_model_serialization = kwargs.setdefault("is_xml", internal_data_type.is_xml_model())
|
715
664
|
else:
|
716
665
|
is_xml_model_serialization = False
|
717
666
|
if internal_data_type and not isinstance(internal_data_type, Enum):
|
@@ -730,13 +679,9 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
730
679
|
attribute_key_case_insensitive_extractor,
|
731
680
|
last_rest_key_case_insensitive_extractor,
|
732
681
|
]
|
733
|
-
data = deserializer._deserialize(
|
734
|
-
data_type, data
|
735
|
-
) # pylint: disable=protected-access
|
682
|
+
data = deserializer._deserialize(data_type, data) # pylint: disable=protected-access
|
736
683
|
except DeserializationError as err:
|
737
|
-
raise SerializationError(
|
738
|
-
"Unable to build a model: " + str(err)
|
739
|
-
) from err
|
684
|
+
raise SerializationError("Unable to build a model: " + str(err)) from err
|
740
685
|
|
741
686
|
return self._serialize(data, data_type, **kwargs)
|
742
687
|
|
@@ -781,9 +726,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
781
726
|
if data_type.startswith("["):
|
782
727
|
internal_data_type = data_type[1:-1]
|
783
728
|
do_quote = not kwargs.get("skip_quote", False)
|
784
|
-
return self.serialize_iter(
|
785
|
-
data, internal_data_type, do_quote=do_quote, **kwargs
|
786
|
-
)
|
729
|
+
return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs)
|
787
730
|
|
788
731
|
# Not a list, regular serialization
|
789
732
|
output = self.serialize_data(data, data_type, **kwargs)
|
@@ -858,9 +801,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
858
801
|
return self._serialize(data, **kwargs)
|
859
802
|
|
860
803
|
@classmethod
|
861
|
-
def _get_custom_serializers(
|
862
|
-
cls, data_type, **kwargs
|
863
|
-
): # pylint: disable=inconsistent-return-statements
|
804
|
+
def _get_custom_serializers(cls, data_type, **kwargs): # pylint: disable=inconsistent-return-statements
|
864
805
|
custom_serializer = kwargs.get("basic_types_serializers", {}).get(data_type)
|
865
806
|
if custom_serializer:
|
866
807
|
return custom_serializer
|
@@ -943,9 +884,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
943
884
|
serialized.append(None)
|
944
885
|
|
945
886
|
if kwargs.get("do_quote", False):
|
946
|
-
serialized = [
|
947
|
-
"" if s is None else quote(str(s), safe="") for s in serialized
|
948
|
-
]
|
887
|
+
serialized = ["" if s is None else quote(str(s), safe="") for s in serialized]
|
949
888
|
|
950
889
|
if div:
|
951
890
|
serialized = ["" if s is None else str(s) for s in serialized]
|
@@ -962,9 +901,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
962
901
|
is_wrapped = xml_desc.get("wrapped", False)
|
963
902
|
node_name = xml_desc.get("itemsName", xml_name)
|
964
903
|
if is_wrapped:
|
965
|
-
final_result = _create_xml_node(
|
966
|
-
xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)
|
967
|
-
)
|
904
|
+
final_result = _create_xml_node(xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None))
|
968
905
|
else:
|
969
906
|
final_result = []
|
970
907
|
# All list elements to "local_node"
|
@@ -972,11 +909,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
972
909
|
if isinstance(el, ET.Element):
|
973
910
|
el_node = el
|
974
911
|
else:
|
975
|
-
el_node = _create_xml_node(
|
976
|
-
node_name,
|
977
|
-
xml_desc.get("prefix", None),
|
978
|
-
xml_desc.get("ns", None),
|
979
|
-
)
|
912
|
+
el_node = _create_xml_node(node_name, xml_desc.get("prefix", None), xml_desc.get("ns", None))
|
980
913
|
if el is not None: # Otherwise it writes "None" :-p
|
981
914
|
el_node.text = str(el)
|
982
915
|
final_result.append(el_node)
|
@@ -995,9 +928,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
995
928
|
serialized = {}
|
996
929
|
for key, value in attr.items():
|
997
930
|
try:
|
998
|
-
serialized[self.serialize_unicode(key)] = self.serialize_data(
|
999
|
-
value, dict_type, **kwargs
|
1000
|
-
)
|
931
|
+
serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs)
|
1001
932
|
except ValueError as err:
|
1002
933
|
if isinstance(err, SerializationError):
|
1003
934
|
raise
|
@@ -1008,18 +939,14 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
1008
939
|
xml_desc = serialization_ctxt["xml"]
|
1009
940
|
xml_name = xml_desc["name"]
|
1010
941
|
|
1011
|
-
final_result = _create_xml_node(
|
1012
|
-
xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)
|
1013
|
-
)
|
942
|
+
final_result = _create_xml_node(xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None))
|
1014
943
|
for key, value in serialized.items():
|
1015
944
|
ET.SubElement(final_result, key).text = value
|
1016
945
|
return final_result
|
1017
946
|
|
1018
947
|
return serialized
|
1019
948
|
|
1020
|
-
def serialize_object(
|
1021
|
-
self, attr, **kwargs
|
1022
|
-
): # pylint: disable=too-many-return-statements
|
949
|
+
def serialize_object(self, attr, **kwargs): # pylint: disable=too-many-return-statements
|
1023
950
|
"""Serialize a generic object.
|
1024
951
|
This will be handled as a dictionary. If object passed in is not
|
1025
952
|
a basic type (str, int, float, dict, list) it will simply be
|
@@ -1059,9 +986,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
1059
986
|
serialized = {}
|
1060
987
|
for key, value in attr.items():
|
1061
988
|
try:
|
1062
|
-
serialized[self.serialize_unicode(key)] = self.serialize_object(
|
1063
|
-
value, **kwargs
|
1064
|
-
)
|
989
|
+
serialized[self.serialize_unicode(key)] = self.serialize_object(value, **kwargs)
|
1065
990
|
except ValueError:
|
1066
991
|
serialized[self.serialize_unicode(key)] = None
|
1067
992
|
return serialized
|
@@ -1221,12 +1146,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
1221
1146
|
if microseconds:
|
1222
1147
|
microseconds = "." + microseconds
|
1223
1148
|
date = "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}".format(
|
1224
|
-
utc.tm_year,
|
1225
|
-
utc.tm_mon,
|
1226
|
-
utc.tm_mday,
|
1227
|
-
utc.tm_hour,
|
1228
|
-
utc.tm_min,
|
1229
|
-
utc.tm_sec,
|
1149
|
+
utc.tm_year, utc.tm_mon, utc.tm_mday, utc.tm_hour, utc.tm_min, utc.tm_sec
|
1230
1150
|
)
|
1231
1151
|
return date + microseconds + "Z"
|
1232
1152
|
except (ValueError, OverflowError) as err:
|
@@ -1289,9 +1209,7 @@ def rest_key_case_insensitive_extractor( # pylint: disable=unused-argument, inc
|
|
1289
1209
|
key = _decode_attribute_map_key(dict_keys[0])
|
1290
1210
|
break
|
1291
1211
|
working_key = _decode_attribute_map_key(dict_keys[0])
|
1292
|
-
working_data = attribute_key_case_insensitive_extractor(
|
1293
|
-
working_key, None, working_data
|
1294
|
-
)
|
1212
|
+
working_data = attribute_key_case_insensitive_extractor(working_key, None, working_data)
|
1295
1213
|
if working_data is None:
|
1296
1214
|
# If at any point while following flatten JSON path see None, it means
|
1297
1215
|
# that all properties under are None as well
|
@@ -1316,9 +1234,7 @@ def last_rest_key_extractor(attr, attr_desc, data): # pylint: disable=unused-ar
|
|
1316
1234
|
return attribute_key_extractor(dict_keys[-1], None, data)
|
1317
1235
|
|
1318
1236
|
|
1319
|
-
def last_rest_key_case_insensitive_extractor(
|
1320
|
-
attr, attr_desc, data
|
1321
|
-
): # pylint: disable=unused-argument
|
1237
|
+
def last_rest_key_case_insensitive_extractor(attr, attr_desc, data): # pylint: disable=unused-argument
|
1322
1238
|
"""Extract the attribute in "data" based on the last part of the JSON path key.
|
1323
1239
|
|
1324
1240
|
This is the case insensitive version of "last_rest_key_extractor"
|
@@ -1363,9 +1279,7 @@ def _extract_name_from_internal_type(internal_type):
|
|
1363
1279
|
return xml_name
|
1364
1280
|
|
1365
1281
|
|
1366
|
-
def xml_key_extractor(
|
1367
|
-
attr, attr_desc, data
|
1368
|
-
): # pylint: disable=unused-argument,too-many-return-statements
|
1282
|
+
def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument,too-many-return-statements
|
1369
1283
|
if isinstance(data, dict):
|
1370
1284
|
return None
|
1371
1285
|
|
@@ -1399,10 +1313,7 @@ def xml_key_extractor(
|
|
1399
1313
|
# - Wrapped node
|
1400
1314
|
# - Internal type is an enum (considered basic types)
|
1401
1315
|
# - Internal type has no XML/Name node
|
1402
|
-
if is_wrapped or (
|
1403
|
-
internal_type
|
1404
|
-
and (issubclass(internal_type, Enum) or "name" not in internal_type_xml_map)
|
1405
|
-
):
|
1316
|
+
if is_wrapped or (internal_type and (issubclass(internal_type, Enum) or "name" not in internal_type_xml_map)):
|
1406
1317
|
children = data.findall(xml_name)
|
1407
1318
|
# If internal type has a local name and it's not a list, I use that name
|
1408
1319
|
elif not is_iter_type and internal_type and "name" in internal_type_xml_map:
|
@@ -1410,9 +1321,7 @@ def xml_key_extractor(
|
|
1410
1321
|
children = data.findall(xml_name)
|
1411
1322
|
# That's an array
|
1412
1323
|
else:
|
1413
|
-
if
|
1414
|
-
internal_type
|
1415
|
-
): # Complex type, ignore itemsName and use the complex type name
|
1324
|
+
if internal_type: # Complex type, ignore itemsName and use the complex type name
|
1416
1325
|
items_name = _extract_name_from_internal_type(internal_type)
|
1417
1326
|
else:
|
1418
1327
|
items_name = xml_desc.get("itemsName", xml_name)
|
@@ -1440,9 +1349,7 @@ def xml_key_extractor(
|
|
1440
1349
|
|
1441
1350
|
# Here it's not a itertype, we should have found one element only or empty
|
1442
1351
|
if len(children) > 1:
|
1443
|
-
raise DeserializationError(
|
1444
|
-
"Find several XML '{}' where it was not expected".format(xml_name)
|
1445
|
-
)
|
1352
|
+
raise DeserializationError("Find several XML '{}' where it was not expected".format(xml_name))
|
1446
1353
|
return children[0]
|
1447
1354
|
|
1448
1355
|
|
@@ -1455,9 +1362,7 @@ class Deserializer:
|
|
1455
1362
|
|
1456
1363
|
basic_types = {str: "str", int: "int", bool: "bool", float: "float"}
|
1457
1364
|
|
1458
|
-
valid_date = re.compile(
|
1459
|
-
r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?"
|
1460
|
-
)
|
1365
|
+
valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?")
|
1461
1366
|
|
1462
1367
|
def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None:
|
1463
1368
|
self.deserialize_type = {
|
@@ -1502,9 +1407,7 @@ class Deserializer:
|
|
1502
1407
|
data = self._unpack_content(response_data, content_type)
|
1503
1408
|
return self._deserialize(target_obj, data)
|
1504
1409
|
|
1505
|
-
def _deserialize(
|
1506
|
-
self, target_obj, data
|
1507
|
-
): # pylint: disable=inconsistent-return-statements
|
1410
|
+
def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return-statements
|
1508
1411
|
"""Call the deserializer on a model.
|
1509
1412
|
|
1510
1413
|
Data needs to be already deserialized as JSON or XML ElementTree
|
@@ -1517,16 +1420,9 @@ class Deserializer:
|
|
1517
1420
|
"""
|
1518
1421
|
# This is already a model, go recursive just in case
|
1519
1422
|
if hasattr(data, "_attribute_map"):
|
1520
|
-
constants = [
|
1521
|
-
name
|
1522
|
-
for name, config in getattr(data, "_validation", {}).items()
|
1523
|
-
if config.get("constant")
|
1524
|
-
]
|
1423
|
+
constants = [name for name, config in getattr(data, "_validation", {}).items() if config.get("constant")]
|
1525
1424
|
try:
|
1526
|
-
for (
|
1527
|
-
attr,
|
1528
|
-
mapconfig,
|
1529
|
-
) in data._attribute_map.items(): # pylint: disable=protected-access
|
1425
|
+
for attr, mapconfig in data._attribute_map.items(): # pylint: disable=protected-access
|
1530
1426
|
if attr in constants:
|
1531
1427
|
continue
|
1532
1428
|
value = getattr(data, attr)
|
@@ -1534,9 +1430,7 @@ class Deserializer:
|
|
1534
1430
|
continue
|
1535
1431
|
local_type = mapconfig["type"]
|
1536
1432
|
internal_data_type = local_type.strip("[]{}")
|
1537
|
-
if internal_data_type not in self.dependencies or isinstance(
|
1538
|
-
internal_data_type, Enum
|
1539
|
-
):
|
1433
|
+
if internal_data_type not in self.dependencies or isinstance(internal_data_type, Enum):
|
1540
1434
|
continue
|
1541
1435
|
setattr(data, attr, self._deserialize(local_type, value))
|
1542
1436
|
return data
|
@@ -1589,10 +1483,7 @@ class Deserializer:
|
|
1589
1483
|
def _build_additional_properties(self, attribute_map, data):
|
1590
1484
|
if not self.additional_properties_detection:
|
1591
1485
|
return None
|
1592
|
-
if (
|
1593
|
-
"additional_properties" in attribute_map
|
1594
|
-
and attribute_map.get("additional_properties", {}).get("key") != ""
|
1595
|
-
):
|
1486
|
+
if "additional_properties" in attribute_map and attribute_map.get("additional_properties", {}).get("key") != "":
|
1596
1487
|
# Check empty string. If it's not empty, someone has a real "additionalProperties"
|
1597
1488
|
return None
|
1598
1489
|
if isinstance(data, ET.Element):
|
@@ -1649,8 +1540,7 @@ class Deserializer:
|
|
1649
1540
|
return self(target_obj, data, content_type=content_type)
|
1650
1541
|
except: # pylint: disable=bare-except
|
1651
1542
|
_LOGGER.debug(
|
1652
|
-
"Ran into a deserialization error. Ignoring since this is failsafe deserialization",
|
1653
|
-
exc_info=True,
|
1543
|
+
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True
|
1654
1544
|
)
|
1655
1545
|
return None
|
1656
1546
|
|
@@ -1678,21 +1568,15 @@ class Deserializer:
|
|
1678
1568
|
if context:
|
1679
1569
|
if RawDeserializer.CONTEXT_NAME in context:
|
1680
1570
|
return context[RawDeserializer.CONTEXT_NAME]
|
1681
|
-
raise ValueError(
|
1682
|
-
"This pipeline didn't have the RawDeserializer policy; can't deserialize"
|
1683
|
-
)
|
1571
|
+
raise ValueError("This pipeline didn't have the RawDeserializer policy; can't deserialize")
|
1684
1572
|
|
1685
1573
|
# Assume this is enough to recognize universal_http.ClientResponse without importing it
|
1686
1574
|
if hasattr(raw_data, "body"):
|
1687
|
-
return RawDeserializer.deserialize_from_http_generics(
|
1688
|
-
raw_data.text(), raw_data.headers
|
1689
|
-
)
|
1575
|
+
return RawDeserializer.deserialize_from_http_generics(raw_data.text(), raw_data.headers)
|
1690
1576
|
|
1691
1577
|
# Assume this enough to recognize requests.Response without importing it.
|
1692
1578
|
if hasattr(raw_data, "_content_consumed"):
|
1693
|
-
return RawDeserializer.deserialize_from_http_generics(
|
1694
|
-
raw_data.text, raw_data.headers
|
1695
|
-
)
|
1579
|
+
return RawDeserializer.deserialize_from_http_generics(raw_data.text, raw_data.headers)
|
1696
1580
|
|
1697
1581
|
if isinstance(raw_data, (str, bytes)) or hasattr(raw_data, "read"):
|
1698
1582
|
return RawDeserializer.deserialize_from_text(raw_data, content_type) # type: ignore
|
@@ -1720,11 +1604,7 @@ class Deserializer:
|
|
1720
1604
|
for k, v in response._validation.items() # pylint: disable=protected-access # type: ignore
|
1721
1605
|
if v.get("constant")
|
1722
1606
|
]
|
1723
|
-
kwargs = {
|
1724
|
-
k: v
|
1725
|
-
for k, v in attrs.items()
|
1726
|
-
if k not in subtype and k not in readonly + const
|
1727
|
-
}
|
1607
|
+
kwargs = {k: v for k, v in attrs.items() if k not in subtype and k not in readonly + const}
|
1728
1608
|
response_obj = response(**kwargs)
|
1729
1609
|
for attr in readonly:
|
1730
1610
|
setattr(response_obj, attr, attrs.get(attr))
|
@@ -1744,9 +1624,7 @@ class Deserializer:
|
|
1744
1624
|
msg += "Type: {}, Error: {}".format(type(response), exp)
|
1745
1625
|
raise DeserializationError(msg) from exp
|
1746
1626
|
|
1747
|
-
def deserialize_data(
|
1748
|
-
self, data, data_type
|
1749
|
-
): # pylint: disable=too-many-return-statements
|
1627
|
+
def deserialize_data(self, data, data_type): # pylint: disable=too-many-return-statements
|
1750
1628
|
"""Process data for deserialization according to data type.
|
1751
1629
|
|
1752
1630
|
:param str data: The response string to be deserialized.
|
@@ -1764,24 +1642,15 @@ class Deserializer:
|
|
1764
1642
|
if data_type in self.basic_types.values():
|
1765
1643
|
return self.deserialize_basic(data, data_type)
|
1766
1644
|
if data_type in self.deserialize_type:
|
1767
|
-
if isinstance(
|
1768
|
-
data, self.deserialize_expected_types.get(data_type, tuple())
|
1769
|
-
):
|
1645
|
+
if isinstance(data, self.deserialize_expected_types.get(data_type, tuple())):
|
1770
1646
|
return data
|
1771
1647
|
|
1772
|
-
is_a_text_parsing_type =
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
]
|
1779
|
-
)
|
1780
|
-
if (
|
1781
|
-
isinstance(data, ET.Element)
|
1782
|
-
and is_a_text_parsing_type(data_type)
|
1783
|
-
and not data.text
|
1784
|
-
):
|
1648
|
+
is_a_text_parsing_type = lambda x: x not in [ # pylint: disable=unnecessary-lambda-assignment
|
1649
|
+
"object",
|
1650
|
+
"[]",
|
1651
|
+
r"{}",
|
1652
|
+
]
|
1653
|
+
if isinstance(data, ET.Element) and is_a_text_parsing_type(data_type) and not data.text:
|
1785
1654
|
return None
|
1786
1655
|
data_val = self.deserialize_type[data_type](data)
|
1787
1656
|
return data_val
|
@@ -1812,16 +1681,10 @@ class Deserializer:
|
|
1812
1681
|
"""
|
1813
1682
|
if attr is None:
|
1814
1683
|
return None
|
1815
|
-
if isinstance(
|
1816
|
-
attr, ET.Element
|
1817
|
-
): # If I receive an element here, get the children
|
1684
|
+
if isinstance(attr, ET.Element): # If I receive an element here, get the children
|
1818
1685
|
attr = list(attr)
|
1819
1686
|
if not isinstance(attr, (list, set)):
|
1820
|
-
raise DeserializationError(
|
1821
|
-
"Cannot deserialize as [{}] an object of type {}".format(
|
1822
|
-
iter_type, type(attr)
|
1823
|
-
)
|
1824
|
-
)
|
1687
|
+
raise DeserializationError("Cannot deserialize as [{}] an object of type {}".format(iter_type, type(attr)))
|
1825
1688
|
return [self.deserialize_data(a, iter_type) for a in attr]
|
1826
1689
|
|
1827
1690
|
def deserialize_dict(self, attr, dict_type):
|
@@ -1834,18 +1697,14 @@ class Deserializer:
|
|
1834
1697
|
:rtype: dict
|
1835
1698
|
"""
|
1836
1699
|
if isinstance(attr, list):
|
1837
|
-
return {
|
1838
|
-
x["key"]: self.deserialize_data(x["value"], dict_type) for x in attr
|
1839
|
-
}
|
1700
|
+
return {x["key"]: self.deserialize_data(x["value"], dict_type) for x in attr}
|
1840
1701
|
|
1841
1702
|
if isinstance(attr, ET.Element):
|
1842
1703
|
# Transform <Key>value</Key> into {"Key": "value"}
|
1843
1704
|
attr = {el.tag: el.text for el in attr}
|
1844
1705
|
return {k: self.deserialize_data(v, dict_type) for k, v in attr.items()}
|
1845
1706
|
|
1846
|
-
def deserialize_object(
|
1847
|
-
self, attr, **kwargs
|
1848
|
-
): # pylint: disable=too-many-return-statements
|
1707
|
+
def deserialize_object(self, attr, **kwargs): # pylint: disable=too-many-return-statements
|
1849
1708
|
"""Deserialize a generic object.
|
1850
1709
|
This will be handled as a dictionary.
|
1851
1710
|
|
@@ -1888,9 +1747,7 @@ class Deserializer:
|
|
1888
1747
|
error = "Cannot deserialize generic object with type: "
|
1889
1748
|
raise TypeError(error + str(obj_type))
|
1890
1749
|
|
1891
|
-
def deserialize_basic(
|
1892
|
-
self, attr, data_type
|
1893
|
-
): # pylint: disable=too-many-return-statements
|
1750
|
+
def deserialize_basic(self, attr, data_type): # pylint: disable=too-many-return-statements
|
1894
1751
|
"""Deserialize basic builtin data type from string.
|
1895
1752
|
Will attempt to convert to str, int, float and bool.
|
1896
1753
|
This function will also accept '1', '0', 'true' and 'false' as
|
@@ -1981,11 +1838,7 @@ class Deserializer:
|
|
1981
1838
|
if enum_value.value.lower() == str(data).lower():
|
1982
1839
|
return enum_value
|
1983
1840
|
# We don't fail anymore for unknown value, we deserialize as a string
|
1984
|
-
_LOGGER.warning(
|
1985
|
-
"Deserializer is not able to find %s as valid enum in %s",
|
1986
|
-
data,
|
1987
|
-
enum_obj,
|
1988
|
-
)
|
1841
|
+
_LOGGER.warning("Deserializer is not able to find %s as valid enum in %s", data, enum_obj)
|
1989
1842
|
return Deserializer.deserialize_unicode(data)
|
1990
1843
|
|
1991
1844
|
@staticmethod
|
@@ -2077,9 +1930,7 @@ class Deserializer:
|
|
2077
1930
|
if isinstance(attr, ET.Element):
|
2078
1931
|
attr = attr.text
|
2079
1932
|
if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore
|
2080
|
-
raise DeserializationError(
|
2081
|
-
"Date must have only digits and -. Received: %s" % attr
|
2082
|
-
)
|
1933
|
+
raise DeserializationError("Date must have only digits and -. Received: %s" % attr)
|
2083
1934
|
# This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
|
2084
1935
|
return isodate.parse_date(attr, defaultmonth=0, defaultday=0)
|
2085
1936
|
|
@@ -2095,9 +1946,7 @@ class Deserializer:
|
|
2095
1946
|
if isinstance(attr, ET.Element):
|
2096
1947
|
attr = attr.text
|
2097
1948
|
if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore
|
2098
|
-
raise DeserializationError(
|
2099
|
-
"Date must have only digits and -. Received: %s" % attr
|
2100
|
-
)
|
1949
|
+
raise DeserializationError("Date must have only digits and -. Received: %s" % attr)
|
2101
1950
|
return isodate.parse_time(attr)
|
2102
1951
|
|
2103
1952
|
@staticmethod
|
@@ -2114,10 +1963,7 @@ class Deserializer:
|
|
2114
1963
|
try:
|
2115
1964
|
parsed_date = email.utils.parsedate_tz(attr) # type: ignore
|
2116
1965
|
date_obj = datetime.datetime(
|
2117
|
-
*parsed_date[:6],
|
2118
|
-
tzinfo=datetime.timezone(
|
2119
|
-
datetime.timedelta(minutes=(parsed_date[9] or 0) / 60)
|
2120
|
-
),
|
1966
|
+
*parsed_date[:6], tzinfo=datetime.timezone(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60))
|
2121
1967
|
)
|
2122
1968
|
if not date_obj.tzinfo:
|
2123
1969
|
date_obj = date_obj.astimezone(tz=TZ_UTC)
|