@typespec/http-client-python 0.6.6 → 0.6.8
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.
- package/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +1 -3
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/types.d.ts.map +1 -1
- package/dist/emitter/types.js +20 -54
- package/dist/emitter/types.js.map +1 -1
- package/dist/emitter/utils.d.ts.map +1 -1
- package/dist/emitter/utils.js +6 -1
- package/dist/emitter/utils.js.map +1 -1
- package/emitter/src/emitter.ts +1 -4
- package/emitter/src/types.ts +25 -57
- package/emitter/src/utils.ts +7 -1
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
- package/generator/build/lib/pygen/codegen/models/code_model.py +1 -1
- package/generator/build/lib/pygen/codegen/models/operation.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +9 -4
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +9 -2
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +61 -0
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +37 -39
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/models/code_model.py +1 -1
- package/generator/pygen/codegen/models/operation.py +1 -1
- package/generator/pygen/codegen/serializers/__init__.py +9 -4
- package/generator/pygen/codegen/serializers/builder_serializer.py +9 -2
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +61 -0
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +37 -39
- package/generator/test/azure/tox.ini +3 -3
- package/generator/test/unbranded/tox.ini +3 -3
- package/package.json +3 -3
|
@@ -372,15 +372,34 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
|
|
|
372
372
|
return not self.__eq__(other)
|
|
373
373
|
|
|
374
374
|
def keys(self) -> typing.KeysView[str]:
|
|
375
|
+
"""
|
|
376
|
+
:returns: a set-like object providing a view on D's keys
|
|
377
|
+
:rtype: ~typing.KeysView
|
|
378
|
+
"""
|
|
375
379
|
return self._data.keys()
|
|
376
380
|
|
|
377
381
|
def values(self) -> typing.ValuesView[typing.Any]:
|
|
382
|
+
"""
|
|
383
|
+
:returns: an object providing a view on D's values
|
|
384
|
+
:rtype: ~typing.ValuesView
|
|
385
|
+
"""
|
|
378
386
|
return self._data.values()
|
|
379
387
|
|
|
380
388
|
def items(self) -> typing.ItemsView[str, typing.Any]:
|
|
389
|
+
"""
|
|
390
|
+
:returns: set-like object providing a view on D's items
|
|
391
|
+
:rtype: ~typing.ItemsView
|
|
392
|
+
"""
|
|
381
393
|
return self._data.items()
|
|
382
394
|
|
|
383
395
|
def get(self, key: str, default: typing.Any = None) -> typing.Any:
|
|
396
|
+
"""
|
|
397
|
+
Get the value for key if key is in the dictionary, else default.
|
|
398
|
+
:param str key: The key to look up.
|
|
399
|
+
:param any default: The value to return if key is not in the dictionary. Defaults to None
|
|
400
|
+
:returns: D[k] if k in D, else d.
|
|
401
|
+
:rtype: any
|
|
402
|
+
"""
|
|
384
403
|
try:
|
|
385
404
|
return self[key]
|
|
386
405
|
except KeyError:
|
|
@@ -396,17 +415,38 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
|
|
|
396
415
|
def pop(self, key: str, default: typing.Any) -> typing.Any: ...
|
|
397
416
|
|
|
398
417
|
def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
|
|
418
|
+
"""
|
|
419
|
+
Removes specified key and return the corresponding value.
|
|
420
|
+
:param str key: The key to pop.
|
|
421
|
+
:param any default: The value to return if key is not in the dictionary
|
|
422
|
+
:returns: The value corresponding to the key.
|
|
423
|
+
:rtype: any
|
|
424
|
+
:raises KeyError: If key is not found and default is not given.
|
|
425
|
+
"""
|
|
399
426
|
if default is _UNSET:
|
|
400
427
|
return self._data.pop(key)
|
|
401
428
|
return self._data.pop(key, default)
|
|
402
429
|
|
|
403
430
|
def popitem(self) -> typing.Tuple[str, typing.Any]:
|
|
431
|
+
"""
|
|
432
|
+
Removes and returns some (key, value) pair
|
|
433
|
+
:returns: The (key, value) pair.
|
|
434
|
+
:rtype: tuple
|
|
435
|
+
:raises KeyError: if D is empty.
|
|
436
|
+
"""
|
|
404
437
|
return self._data.popitem()
|
|
405
438
|
|
|
406
439
|
def clear(self) -> None:
|
|
440
|
+
"""
|
|
441
|
+
Remove all items from D.
|
|
442
|
+
"""
|
|
407
443
|
self._data.clear()
|
|
408
444
|
|
|
409
445
|
def update(self, *args: typing.Any, **kwargs: typing.Any) -> None:
|
|
446
|
+
"""
|
|
447
|
+
Updates D from mapping/iterable E and F.
|
|
448
|
+
:param any args: Either a mapping object or an iterable of key-value pairs.
|
|
449
|
+
"""
|
|
410
450
|
self._data.update(*args, **kwargs)
|
|
411
451
|
|
|
412
452
|
@typing.overload
|
|
@@ -416,6 +456,13 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
|
|
|
416
456
|
def setdefault(self, key: str, default: typing.Any) -> typing.Any: ...
|
|
417
457
|
|
|
418
458
|
def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
|
|
459
|
+
"""
|
|
460
|
+
Same as calling D.get(k, d), and setting D[k]=d if k not found
|
|
461
|
+
:param str key: The key to look up.
|
|
462
|
+
:param any default: The value to set if key is not in the dictionary
|
|
463
|
+
:returns: D[k] if k in D, else d.
|
|
464
|
+
:rtype: any
|
|
465
|
+
"""
|
|
419
466
|
if default is _UNSET:
|
|
420
467
|
return self._data.setdefault(key)
|
|
421
468
|
return self._data.setdefault(key, default)
|
|
@@ -909,6 +956,20 @@ def _failsafe_deserialize(
|
|
|
909
956
|
return None
|
|
910
957
|
|
|
911
958
|
|
|
959
|
+
def _failsafe_deserialize_xml(
|
|
960
|
+
deserializer: typing.Any,
|
|
961
|
+
value: typing.Any,
|
|
962
|
+
) -> typing.Any:
|
|
963
|
+
try:
|
|
964
|
+
return _deserialize_xml(deserializer, value)
|
|
965
|
+
except DeserializationError:
|
|
966
|
+
_LOGGER.warning(
|
|
967
|
+
"Ran into a deserialization error. Ignoring since this is failsafe deserialization",
|
|
968
|
+
exc_info=True
|
|
969
|
+
)
|
|
970
|
+
return None
|
|
971
|
+
|
|
972
|
+
|
|
912
973
|
class _RestField:
|
|
913
974
|
def __init__(
|
|
914
975
|
self,
|
|
@@ -47,9 +47,7 @@ from typing import (
|
|
|
47
47
|
IO,
|
|
48
48
|
Mapping,
|
|
49
49
|
Callable,
|
|
50
|
-
TypeVar,
|
|
51
50
|
MutableMapping,
|
|
52
|
-
Type,
|
|
53
51
|
List,
|
|
54
52
|
)
|
|
55
53
|
|
|
@@ -60,13 +58,13 @@ except ImportError:
|
|
|
60
58
|
import xml.etree.ElementTree as ET
|
|
61
59
|
|
|
62
60
|
import isodate # type: ignore
|
|
61
|
+
from typing_extensions import Self
|
|
63
62
|
|
|
64
63
|
from {{ code_model.core_library }}.exceptions import DeserializationError, SerializationError
|
|
65
64
|
from {{ code_model.core_library }}.serialization import NULL as CoreNull
|
|
66
65
|
|
|
67
66
|
_BOM = codecs.BOM_UTF8.decode(encoding="utf-8")
|
|
68
67
|
|
|
69
|
-
ModelType = TypeVar("ModelType", bound="Model")
|
|
70
68
|
JSON = MutableMapping[str, Any]
|
|
71
69
|
|
|
72
70
|
|
|
@@ -383,25 +381,25 @@ class Model:
|
|
|
383
381
|
return client_models
|
|
384
382
|
|
|
385
383
|
@classmethod
|
|
386
|
-
def deserialize(cls
|
|
384
|
+
def deserialize(cls, data: Any, content_type: Optional[str] = None) -> Self:
|
|
387
385
|
"""Parse a str using the RestAPI syntax and return a model.
|
|
388
386
|
|
|
389
387
|
:param str data: A str using RestAPI structure. JSON by default.
|
|
390
388
|
:param str content_type: JSON by default, set application/xml if XML.
|
|
391
389
|
:returns: An instance of this model
|
|
392
|
-
:raises
|
|
393
|
-
:rtype:
|
|
390
|
+
:raises DeserializationError: if something went wrong
|
|
391
|
+
:rtype: Self
|
|
394
392
|
"""
|
|
395
393
|
deserializer = Deserializer(cls._infer_class_models())
|
|
396
394
|
return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
|
|
397
395
|
|
|
398
396
|
@classmethod
|
|
399
397
|
def from_dict(
|
|
400
|
-
cls
|
|
398
|
+
cls,
|
|
401
399
|
data: Any,
|
|
402
400
|
key_extractors: Optional[Callable[[str, Dict[str, Any], Any], Any]] = None,
|
|
403
401
|
content_type: Optional[str] = None,
|
|
404
|
-
) ->
|
|
402
|
+
) -> Self:
|
|
405
403
|
"""Parse a dict using given key extractor return a model.
|
|
406
404
|
|
|
407
405
|
By default consider key
|
|
@@ -413,7 +411,7 @@ class Model:
|
|
|
413
411
|
:param str content_type: JSON by default, set application/xml if XML.
|
|
414
412
|
:returns: An instance of this model
|
|
415
413
|
:raises: DeserializationError if something went wrong
|
|
416
|
-
:rtype:
|
|
414
|
+
:rtype: Self
|
|
417
415
|
"""
|
|
418
416
|
deserializer = Deserializer(cls._infer_class_models())
|
|
419
417
|
deserializer.key_extractors = ( # type: ignore
|
|
@@ -559,7 +557,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
559
557
|
:param object target_obj: The data to be serialized.
|
|
560
558
|
:param str data_type: The type to be serialized from.
|
|
561
559
|
:rtype: str, dict
|
|
562
|
-
:raises
|
|
560
|
+
:raises SerializationError: if serialization fails.
|
|
563
561
|
:returns: The serialized data.
|
|
564
562
|
"""
|
|
565
563
|
key_transformer = kwargs.get("key_transformer", self.key_transformer)
|
|
@@ -669,8 +667,8 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
669
667
|
:param object data: The data to be serialized.
|
|
670
668
|
:param str data_type: The type to be serialized from.
|
|
671
669
|
:rtype: dict
|
|
672
|
-
:raises
|
|
673
|
-
:raises
|
|
670
|
+
:raises SerializationError: if serialization fails.
|
|
671
|
+
:raises ValueError: if data is None
|
|
674
672
|
:returns: The serialized request body
|
|
675
673
|
"""
|
|
676
674
|
|
|
@@ -714,8 +712,8 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
714
712
|
:param str data_type: The type to be serialized from.
|
|
715
713
|
:rtype: str
|
|
716
714
|
:returns: The serialized URL path
|
|
717
|
-
:raises
|
|
718
|
-
:raises
|
|
715
|
+
:raises TypeError: if serialization fails.
|
|
716
|
+
:raises ValueError: if data is None
|
|
719
717
|
"""
|
|
720
718
|
try:
|
|
721
719
|
output = self.serialize_data(data, data_type, **kwargs)
|
|
@@ -738,8 +736,8 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
738
736
|
:param object data: The data to be serialized.
|
|
739
737
|
:param str data_type: The type to be serialized from.
|
|
740
738
|
:rtype: str, list
|
|
741
|
-
:raises
|
|
742
|
-
:raises
|
|
739
|
+
:raises TypeError: if serialization fails.
|
|
740
|
+
:raises ValueError: if data is None
|
|
743
741
|
:returns: The serialized query parameter
|
|
744
742
|
"""
|
|
745
743
|
try:
|
|
@@ -768,8 +766,8 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
768
766
|
:param object data: The data to be serialized.
|
|
769
767
|
:param str data_type: The type to be serialized from.
|
|
770
768
|
:rtype: str
|
|
771
|
-
:raises
|
|
772
|
-
:raises
|
|
769
|
+
:raises TypeError: if serialization fails.
|
|
770
|
+
:raises ValueError: if data is None
|
|
773
771
|
:returns: The serialized header
|
|
774
772
|
"""
|
|
775
773
|
try:
|
|
@@ -788,9 +786,9 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
788
786
|
|
|
789
787
|
:param object data: The data to be serialized.
|
|
790
788
|
:param str data_type: The type to be serialized from.
|
|
791
|
-
:raises
|
|
792
|
-
:raises
|
|
793
|
-
:raises
|
|
789
|
+
:raises AttributeError: if required data is None.
|
|
790
|
+
:raises ValueError: if data is None
|
|
791
|
+
:raises SerializationError: if serialization fails.
|
|
794
792
|
:returns: The serialized data.
|
|
795
793
|
:rtype: str, int, float, bool, dict, list
|
|
796
794
|
"""
|
|
@@ -1125,7 +1123,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
1125
1123
|
|
|
1126
1124
|
:param Datetime attr: Object to be serialized.
|
|
1127
1125
|
:rtype: str
|
|
1128
|
-
:raises
|
|
1126
|
+
:raises TypeError: if format invalid.
|
|
1129
1127
|
:return: serialized rfc
|
|
1130
1128
|
"""
|
|
1131
1129
|
try:
|
|
@@ -1151,7 +1149,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
1151
1149
|
|
|
1152
1150
|
:param Datetime attr: Object to be serialized.
|
|
1153
1151
|
:rtype: str
|
|
1154
|
-
:raises
|
|
1152
|
+
:raises SerializationError: if format invalid.
|
|
1155
1153
|
:return: serialized iso
|
|
1156
1154
|
"""
|
|
1157
1155
|
if isinstance(attr, str):
|
|
@@ -1184,7 +1182,7 @@ class Serializer: # pylint: disable=too-many-public-methods
|
|
|
1184
1182
|
|
|
1185
1183
|
:param Datetime attr: Object to be serialized.
|
|
1186
1184
|
:rtype: int
|
|
1187
|
-
:raises
|
|
1185
|
+
:raises SerializationError: if format invalid
|
|
1188
1186
|
:return: serialied unix
|
|
1189
1187
|
"""
|
|
1190
1188
|
if isinstance(attr, int):
|
|
@@ -1421,7 +1419,7 @@ class Deserializer:
|
|
|
1421
1419
|
:param str target_obj: Target data type to deserialize to.
|
|
1422
1420
|
:param requests.Response response_data: REST response object.
|
|
1423
1421
|
:param str content_type: Swagger "produces" if available.
|
|
1424
|
-
:raises
|
|
1422
|
+
:raises DeserializationError: if deserialization fails.
|
|
1425
1423
|
:return: Deserialized object.
|
|
1426
1424
|
:rtype: object
|
|
1427
1425
|
"""
|
|
@@ -1435,7 +1433,7 @@ class Deserializer:
|
|
|
1435
1433
|
|
|
1436
1434
|
:param str target_obj: Target data type to deserialize to.
|
|
1437
1435
|
:param object data: Object to deserialize.
|
|
1438
|
-
:raises
|
|
1436
|
+
:raises DeserializationError: if deserialization fails.
|
|
1439
1437
|
:return: Deserialized object.
|
|
1440
1438
|
:rtype: object
|
|
1441
1439
|
"""
|
|
@@ -1650,7 +1648,7 @@ class Deserializer:
|
|
|
1650
1648
|
|
|
1651
1649
|
:param str data: The response string to be deserialized.
|
|
1652
1650
|
:param str data_type: The type to deserialize to.
|
|
1653
|
-
:raises
|
|
1651
|
+
:raises DeserializationError: if deserialization fails.
|
|
1654
1652
|
:return: Deserialized object.
|
|
1655
1653
|
:rtype: object
|
|
1656
1654
|
"""
|
|
@@ -1732,7 +1730,7 @@ class Deserializer:
|
|
|
1732
1730
|
:param dict attr: Dictionary to be deserialized.
|
|
1733
1731
|
:return: Deserialized object.
|
|
1734
1732
|
:rtype: dict
|
|
1735
|
-
:raises
|
|
1733
|
+
:raises TypeError: if non-builtin datatype encountered.
|
|
1736
1734
|
"""
|
|
1737
1735
|
if attr is None:
|
|
1738
1736
|
return None
|
|
@@ -1778,7 +1776,7 @@ class Deserializer:
|
|
|
1778
1776
|
:param str data_type: deserialization data type.
|
|
1779
1777
|
:return: Deserialized basic type.
|
|
1780
1778
|
:rtype: str, int, float or bool
|
|
1781
|
-
:raises
|
|
1779
|
+
:raises TypeError: if string format is not valid.
|
|
1782
1780
|
"""
|
|
1783
1781
|
# If we're here, data is supposed to be a basic type.
|
|
1784
1782
|
# If it's still an XML node, take the text
|
|
@@ -1869,7 +1867,7 @@ class Deserializer:
|
|
|
1869
1867
|
:param str attr: response string to be deserialized.
|
|
1870
1868
|
:return: Deserialized bytearray
|
|
1871
1869
|
:rtype: bytearray
|
|
1872
|
-
:raises
|
|
1870
|
+
:raises TypeError: if string format invalid.
|
|
1873
1871
|
"""
|
|
1874
1872
|
if isinstance(attr, ET.Element):
|
|
1875
1873
|
attr = attr.text
|
|
@@ -1882,7 +1880,7 @@ class Deserializer:
|
|
|
1882
1880
|
:param str attr: response string to be deserialized.
|
|
1883
1881
|
:return: Deserialized base64 string
|
|
1884
1882
|
:rtype: bytearray
|
|
1885
|
-
:raises
|
|
1883
|
+
:raises TypeError: if string format invalid.
|
|
1886
1884
|
"""
|
|
1887
1885
|
if isinstance(attr, ET.Element):
|
|
1888
1886
|
attr = attr.text
|
|
@@ -1897,7 +1895,7 @@ class Deserializer:
|
|
|
1897
1895
|
|
|
1898
1896
|
:param str attr: response string to be deserialized.
|
|
1899
1897
|
:return: Deserialized decimal
|
|
1900
|
-
:raises
|
|
1898
|
+
:raises DeserializationError: if string format invalid.
|
|
1901
1899
|
:rtype: decimal
|
|
1902
1900
|
"""
|
|
1903
1901
|
if isinstance(attr, ET.Element):
|
|
@@ -1915,7 +1913,7 @@ class Deserializer:
|
|
|
1915
1913
|
:param str attr: response string to be deserialized.
|
|
1916
1914
|
:return: Deserialized int
|
|
1917
1915
|
:rtype: long or int
|
|
1918
|
-
:raises
|
|
1916
|
+
:raises ValueError: if string format invalid.
|
|
1919
1917
|
"""
|
|
1920
1918
|
if isinstance(attr, ET.Element):
|
|
1921
1919
|
attr = attr.text
|
|
@@ -1928,7 +1926,7 @@ class Deserializer:
|
|
|
1928
1926
|
:param str attr: response string to be deserialized.
|
|
1929
1927
|
:return: Deserialized duration
|
|
1930
1928
|
:rtype: TimeDelta
|
|
1931
|
-
:raises
|
|
1929
|
+
:raises DeserializationError: if string format invalid.
|
|
1932
1930
|
"""
|
|
1933
1931
|
if isinstance(attr, ET.Element):
|
|
1934
1932
|
attr = attr.text
|
|
@@ -1946,7 +1944,7 @@ class Deserializer:
|
|
|
1946
1944
|
:param str attr: response string to be deserialized.
|
|
1947
1945
|
:return: Deserialized date
|
|
1948
1946
|
:rtype: Date
|
|
1949
|
-
:raises
|
|
1947
|
+
:raises DeserializationError: if string format invalid.
|
|
1950
1948
|
"""
|
|
1951
1949
|
if isinstance(attr, ET.Element):
|
|
1952
1950
|
attr = attr.text
|
|
@@ -1962,7 +1960,7 @@ class Deserializer:
|
|
|
1962
1960
|
:param str attr: response string to be deserialized.
|
|
1963
1961
|
:return: Deserialized time
|
|
1964
1962
|
:rtype: datetime.time
|
|
1965
|
-
:raises
|
|
1963
|
+
:raises DeserializationError: if string format invalid.
|
|
1966
1964
|
"""
|
|
1967
1965
|
if isinstance(attr, ET.Element):
|
|
1968
1966
|
attr = attr.text
|
|
@@ -1977,7 +1975,7 @@ class Deserializer:
|
|
|
1977
1975
|
:param str attr: response string to be deserialized.
|
|
1978
1976
|
:return: Deserialized RFC datetime
|
|
1979
1977
|
:rtype: Datetime
|
|
1980
|
-
:raises
|
|
1978
|
+
:raises DeserializationError: if string format invalid.
|
|
1981
1979
|
"""
|
|
1982
1980
|
if isinstance(attr, ET.Element):
|
|
1983
1981
|
attr = attr.text
|
|
@@ -2000,7 +1998,7 @@ class Deserializer:
|
|
|
2000
1998
|
:param str attr: response string to be deserialized.
|
|
2001
1999
|
:return: Deserialized ISO datetime
|
|
2002
2000
|
:rtype: Datetime
|
|
2003
|
-
:raises
|
|
2001
|
+
:raises DeserializationError: if string format invalid.
|
|
2004
2002
|
"""
|
|
2005
2003
|
if isinstance(attr, ET.Element):
|
|
2006
2004
|
attr = attr.text
|
|
@@ -2038,7 +2036,7 @@ class Deserializer:
|
|
|
2038
2036
|
:param int attr: Object to be serialized.
|
|
2039
2037
|
:return: Deserialized datetime
|
|
2040
2038
|
:rtype: Datetime
|
|
2041
|
-
:raises
|
|
2039
|
+
:raises DeserializationError: if format invalid
|
|
2042
2040
|
"""
|
|
2043
2041
|
if isinstance(attr, ET.Element):
|
|
2044
2042
|
attr = int(attr.text) # type: ignore
|
|
Binary file
|
|
@@ -313,7 +313,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
313
313
|
:param int schema_id: The yaml id of the schema
|
|
314
314
|
:return: If created, we return the created schema, otherwise, we throw.
|
|
315
315
|
:rtype: ~autorest.models.BaseType
|
|
316
|
-
:raises
|
|
316
|
+
:raises KeyError: if schema is not found
|
|
317
317
|
"""
|
|
318
318
|
try:
|
|
319
319
|
return next(type for id, type in self.types_map.items() if id == schema_id)
|
|
@@ -456,7 +456,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
456
456
|
ImportType.LOCAL,
|
|
457
457
|
)
|
|
458
458
|
file_import.add_import("json", ImportType.STDLIB)
|
|
459
|
-
if any(xml_serializable(str(r.default_content_type)) for r in self.responses):
|
|
459
|
+
if any(xml_serializable(str(r.default_content_type)) for r in self.responses + self.exceptions):
|
|
460
460
|
file_import.add_submodule_import(relative_path, "_deserialize_xml", ImportType.LOCAL)
|
|
461
461
|
elif self.need_deserialize:
|
|
462
462
|
file_import.add_submodule_import(relative_path, "_deserialize", ImportType.LOCAL)
|
|
@@ -130,10 +130,10 @@ class JinjaSerializer(ReaderAndWriter):
|
|
|
130
130
|
if self.code_model.options["package_mode"]:
|
|
131
131
|
self._serialize_and_write_package_files(client_namespace)
|
|
132
132
|
|
|
133
|
-
# write
|
|
133
|
+
# write apiview-properties.json
|
|
134
134
|
if self.code_model.options.get("emit_cross_language_definition_file"):
|
|
135
135
|
self.write_file(
|
|
136
|
-
exec_path / Path("
|
|
136
|
+
exec_path / Path("apiview-properties.json"),
|
|
137
137
|
general_serializer.serialize_cross_language_definition_file(),
|
|
138
138
|
)
|
|
139
139
|
|
|
@@ -479,7 +479,12 @@ class JinjaSerializer(ReaderAndWriter):
|
|
|
479
479
|
else Path(".")
|
|
480
480
|
)
|
|
481
481
|
|
|
482
|
+
def exec_path_for_test_sample(self, namespace: str) -> Path:
|
|
483
|
+
return self.exec_path_compensation / Path(*namespace.split("."))
|
|
484
|
+
|
|
482
485
|
def exec_path(self, namespace: str) -> Path:
|
|
486
|
+
if self.code_model.options["no_namespace_folders"] and not self.code_model.options["multiapi"]:
|
|
487
|
+
return Path(".")
|
|
483
488
|
return self.exec_path_compensation / Path(*namespace.split("."))
|
|
484
489
|
|
|
485
490
|
@property
|
|
@@ -492,7 +497,7 @@ class JinjaSerializer(ReaderAndWriter):
|
|
|
492
497
|
return Path("")
|
|
493
498
|
|
|
494
499
|
def _serialize_and_write_sample(self, env: Environment, namespace: str):
|
|
495
|
-
out_path = self.
|
|
500
|
+
out_path = self.exec_path_for_test_sample(namespace) / Path("generated_samples")
|
|
496
501
|
for client in self.code_model.clients:
|
|
497
502
|
for op_group in client.operation_groups:
|
|
498
503
|
for operation in op_group.operations:
|
|
@@ -526,7 +531,7 @@ class JinjaSerializer(ReaderAndWriter):
|
|
|
526
531
|
|
|
527
532
|
def _serialize_and_write_test(self, env: Environment, namespace: str):
|
|
528
533
|
self.code_model.for_test = True
|
|
529
|
-
out_path = self.
|
|
534
|
+
out_path = self.exec_path_for_test_sample(namespace) / Path("generated_tests")
|
|
530
535
|
general_serializer = TestGeneralSerializer(code_model=self.code_model, env=env)
|
|
531
536
|
self.write_file(out_path / "conftest.py", general_serializer.serialize_conftest())
|
|
532
537
|
if not self.code_model.options["azure_arm"]:
|
|
@@ -1005,7 +1005,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
|
|
|
1005
1005
|
retval.extend(deserialize_code)
|
|
1006
1006
|
return retval
|
|
1007
1007
|
|
|
1008
|
-
def handle_error_response(self, builder: OperationType) -> List[str]:
|
|
1008
|
+
def handle_error_response(self, builder: OperationType) -> List[str]: # pylint: disable=too-many-statements, too-many-branches
|
|
1009
1009
|
async_await = "await " if self.async_mode else ""
|
|
1010
1010
|
retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
|
|
1011
1011
|
response_read = [
|
|
@@ -1079,7 +1079,14 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
|
|
|
1079
1079
|
is_operation_file=True, skip_quote=True, serialize_namespace=self.serialize_namespace
|
|
1080
1080
|
)
|
|
1081
1081
|
if self.code_model.options["models_mode"] == "dpg":
|
|
1082
|
-
|
|
1082
|
+
if xml_serializable(str(e.default_content_type)):
|
|
1083
|
+
retval.append(
|
|
1084
|
+
f" error = _failsafe_deserialize_xml({type_annotation}, response.text())"
|
|
1085
|
+
)
|
|
1086
|
+
else:
|
|
1087
|
+
retval.append(
|
|
1088
|
+
f" error = _failsafe_deserialize({type_annotation}, response.json())"
|
|
1089
|
+
)
|
|
1083
1090
|
else:
|
|
1084
1091
|
retval.append(
|
|
1085
1092
|
f" error = self._deserialize.failsafe_deserialize({type_annotation}, "
|
|
@@ -372,15 +372,34 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
|
|
|
372
372
|
return not self.__eq__(other)
|
|
373
373
|
|
|
374
374
|
def keys(self) -> typing.KeysView[str]:
|
|
375
|
+
"""
|
|
376
|
+
:returns: a set-like object providing a view on D's keys
|
|
377
|
+
:rtype: ~typing.KeysView
|
|
378
|
+
"""
|
|
375
379
|
return self._data.keys()
|
|
376
380
|
|
|
377
381
|
def values(self) -> typing.ValuesView[typing.Any]:
|
|
382
|
+
"""
|
|
383
|
+
:returns: an object providing a view on D's values
|
|
384
|
+
:rtype: ~typing.ValuesView
|
|
385
|
+
"""
|
|
378
386
|
return self._data.values()
|
|
379
387
|
|
|
380
388
|
def items(self) -> typing.ItemsView[str, typing.Any]:
|
|
389
|
+
"""
|
|
390
|
+
:returns: set-like object providing a view on D's items
|
|
391
|
+
:rtype: ~typing.ItemsView
|
|
392
|
+
"""
|
|
381
393
|
return self._data.items()
|
|
382
394
|
|
|
383
395
|
def get(self, key: str, default: typing.Any = None) -> typing.Any:
|
|
396
|
+
"""
|
|
397
|
+
Get the value for key if key is in the dictionary, else default.
|
|
398
|
+
:param str key: The key to look up.
|
|
399
|
+
:param any default: The value to return if key is not in the dictionary. Defaults to None
|
|
400
|
+
:returns: D[k] if k in D, else d.
|
|
401
|
+
:rtype: any
|
|
402
|
+
"""
|
|
384
403
|
try:
|
|
385
404
|
return self[key]
|
|
386
405
|
except KeyError:
|
|
@@ -396,17 +415,38 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
|
|
|
396
415
|
def pop(self, key: str, default: typing.Any) -> typing.Any: ...
|
|
397
416
|
|
|
398
417
|
def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
|
|
418
|
+
"""
|
|
419
|
+
Removes specified key and return the corresponding value.
|
|
420
|
+
:param str key: The key to pop.
|
|
421
|
+
:param any default: The value to return if key is not in the dictionary
|
|
422
|
+
:returns: The value corresponding to the key.
|
|
423
|
+
:rtype: any
|
|
424
|
+
:raises KeyError: If key is not found and default is not given.
|
|
425
|
+
"""
|
|
399
426
|
if default is _UNSET:
|
|
400
427
|
return self._data.pop(key)
|
|
401
428
|
return self._data.pop(key, default)
|
|
402
429
|
|
|
403
430
|
def popitem(self) -> typing.Tuple[str, typing.Any]:
|
|
431
|
+
"""
|
|
432
|
+
Removes and returns some (key, value) pair
|
|
433
|
+
:returns: The (key, value) pair.
|
|
434
|
+
:rtype: tuple
|
|
435
|
+
:raises KeyError: if D is empty.
|
|
436
|
+
"""
|
|
404
437
|
return self._data.popitem()
|
|
405
438
|
|
|
406
439
|
def clear(self) -> None:
|
|
440
|
+
"""
|
|
441
|
+
Remove all items from D.
|
|
442
|
+
"""
|
|
407
443
|
self._data.clear()
|
|
408
444
|
|
|
409
445
|
def update(self, *args: typing.Any, **kwargs: typing.Any) -> None:
|
|
446
|
+
"""
|
|
447
|
+
Updates D from mapping/iterable E and F.
|
|
448
|
+
:param any args: Either a mapping object or an iterable of key-value pairs.
|
|
449
|
+
"""
|
|
410
450
|
self._data.update(*args, **kwargs)
|
|
411
451
|
|
|
412
452
|
@typing.overload
|
|
@@ -416,6 +456,13 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
|
|
|
416
456
|
def setdefault(self, key: str, default: typing.Any) -> typing.Any: ...
|
|
417
457
|
|
|
418
458
|
def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
|
|
459
|
+
"""
|
|
460
|
+
Same as calling D.get(k, d), and setting D[k]=d if k not found
|
|
461
|
+
:param str key: The key to look up.
|
|
462
|
+
:param any default: The value to set if key is not in the dictionary
|
|
463
|
+
:returns: D[k] if k in D, else d.
|
|
464
|
+
:rtype: any
|
|
465
|
+
"""
|
|
419
466
|
if default is _UNSET:
|
|
420
467
|
return self._data.setdefault(key)
|
|
421
468
|
return self._data.setdefault(key, default)
|
|
@@ -909,6 +956,20 @@ def _failsafe_deserialize(
|
|
|
909
956
|
return None
|
|
910
957
|
|
|
911
958
|
|
|
959
|
+
def _failsafe_deserialize_xml(
|
|
960
|
+
deserializer: typing.Any,
|
|
961
|
+
value: typing.Any,
|
|
962
|
+
) -> typing.Any:
|
|
963
|
+
try:
|
|
964
|
+
return _deserialize_xml(deserializer, value)
|
|
965
|
+
except DeserializationError:
|
|
966
|
+
_LOGGER.warning(
|
|
967
|
+
"Ran into a deserialization error. Ignoring since this is failsafe deserialization",
|
|
968
|
+
exc_info=True
|
|
969
|
+
)
|
|
970
|
+
return None
|
|
971
|
+
|
|
972
|
+
|
|
912
973
|
class _RestField:
|
|
913
974
|
def __init__(
|
|
914
975
|
self,
|