2
2
# coding=utf-8
3
3
# --------------------------------------------------------------------------
4
4
# Copyright (c) Microsoft Corporation. All rights reserved.
5
- # Licensed under the MIT License. See License.txt in the project root for
6
- # license information.
5
+ # Licensed under the MIT License. See License.txt in the project root for license information.
6
+ # Code generated by Microsoft (R) Python Code Generator.
7
+ # Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
8
# --------------------------------------------------------------------------
8
- # pylint: disable=protected-access, arguments-differ, signature-differs, broad-except, too-many-lines
9
+ # pylint: disable=protected-access, broad-except
9
10
10
11
import copy
11
12
import calendar
21
22
from datetime import datetime , date , time , timedelta , timezone
22
23
from json import JSONEncoder
23
24
import xml .etree .ElementTree as ET
25
+ from collections .abc import MutableMapping
24
26
from typing_extensions import Self
25
27
import isodate
26
28
from azure .core .exceptions import DeserializationError
27
29
from azure .core import CaseInsensitiveEnumMeta
28
30
from azure .core .pipeline import PipelineResponse
29
31
from azure .core .serialization import _Null
30
32
31
- if sys .version_info >= (3 , 9 ):
32
- from collections .abc import MutableMapping
33
- else :
34
- from typing import MutableMapping
35
-
36
33
_LOGGER = logging .getLogger (__name__ )
37
34
38
35
__all__ = ["SdkJSONEncoder" , "Model" , "rest_field" , "rest_discriminator" ]
@@ -347,7 +344,7 @@ def _get_model(module_name: str, model_name: str):
347
344
_UNSET = object ()
348
345
349
346
350
- class _MyMutableMapping (MutableMapping [str , typing .Any ]): # pylint: disable=unsubscriptable-object
347
+ class _MyMutableMapping (MutableMapping [str , typing .Any ]):
351
348
def __init__ (self , data : typing .Dict [str , typing .Any ]) -> None :
352
349
self ._data = data
353
350
@@ -373,50 +370,97 @@ def __ne__(self, other: typing.Any) -> bool:
373
370
return not self .__eq__ (other )
374
371
375
372
def keys (self ) -> typing .KeysView [str ]:
373
+ """
374
+ :returns: a set-like object providing a view on D's keys
375
+ :rtype: ~typing.KeysView
376
+ """
376
377
return self ._data .keys ()
377
378
378
379
def values (self ) -> typing .ValuesView [typing .Any ]:
380
+ """
381
+ :returns: an object providing a view on D's values
382
+ :rtype: ~typing.ValuesView
383
+ """
379
384
return self ._data .values ()
380
385
381
386
def items (self ) -> typing .ItemsView [str , typing .Any ]:
387
+ """
388
+ :returns: set-like object providing a view on D's items
389
+ :rtype: ~typing.ItemsView
390
+ """
382
391
return self ._data .items ()
383
392
384
393
def get (self , key : str , default : typing .Any = None ) -> typing .Any :
394
+ """
395
+ Get the value for key if key is in the dictionary, else default.
396
+ :param str key: The key to look up.
397
+ :param any default: The value to return if key is not in the dictionary. Defaults to None
398
+ :returns: D[k] if k in D, else d.
399
+ :rtype: any
400
+ """
385
401
try :
386
402
return self [key ]
387
403
except KeyError :
388
404
return default
389
405
390
406
@typing .overload
391
- def pop (self , key : str ) -> typing .Any : ...
407
+ def pop (self , key : str ) -> typing .Any : ... # pylint: disable=arguments-differ
392
408
393
409
@typing .overload
394
- def pop (self , key : str , default : _T ) -> _T : ...
410
+ def pop (self , key : str , default : _T ) -> _T : ... # pylint: disable=signature-differs
395
411
396
412
@typing .overload
397
- def pop (self , key : str , default : typing .Any ) -> typing .Any : ...
413
+ def pop (self , key : str , default : typing .Any ) -> typing .Any : ... # pylint: disable=signature-differs
398
414
399
415
def pop (self , key : str , default : typing .Any = _UNSET ) -> typing .Any :
416
+ """
417
+ Removes specified key and return the corresponding value.
418
+ :param str key: The key to pop.
419
+ :param any default: The value to return if key is not in the dictionary
420
+ :returns: The value corresponding to the key.
421
+ :rtype: any
422
+ :raises KeyError: If key is not found and default is not given.
423
+ """
400
424
if default is _UNSET :
401
425
return self ._data .pop (key )
402
426
return self ._data .pop (key , default )
403
427
404
428
def popitem (self ) -> typing .Tuple [str , typing .Any ]:
429
+ """
430
+ Removes and returns some (key, value) pair
431
+ :returns: The (key, value) pair.
432
+ :rtype: tuple
433
+ :raises KeyError: if D is empty.
434
+ """
405
435
return self ._data .popitem ()
406
436
407
437
def clear (self ) -> None :
438
+ """
439
+ Remove all items from D.
440
+ """
408
441
self ._data .clear ()
409
442
410
- def update (self , * args : typing .Any , ** kwargs : typing .Any ) -> None :
443
+ def update (self , * args : typing .Any , ** kwargs : typing .Any ) -> None : # pylint: disable=arguments-differ
444
+ """
445
+ Updates D from mapping/iterable E and F.
446
+ :param any args: Either a mapping object or an iterable of key-value pairs.
447
+ """
411
448
self ._data .update (* args , ** kwargs )
412
449
413
450
@typing .overload
414
451
def setdefault (self , key : str , default : None = None ) -> None : ...
415
452
416
453
@typing .overload
417
- def setdefault (self , key : str , default : typing .Any ) -> typing .Any : ...
454
+ def setdefault (self , key : str , default : typing .Any ) -> typing .Any : ... # pylint: disable=signature-differs
418
455
419
456
def setdefault (self , key : str , default : typing .Any = _UNSET ) -> typing .Any :
457
+ """
458
+ Same as calling D.get(k, d), and setting D[k]=d if k not found
459
+ :param str key: The key to look up.
460
+ :param any default: The value to set if key is not in the dictionary
461
+ :returns: D[k] if k in D, else d.
462
+ :rtype: any
463
+ """
420
464
if default is _UNSET :
421
465
return self ._data .setdefault (key )
422
466
return self ._data .setdefault (key , default )
@@ -574,7 +618,7 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
574
618
def copy (self ) -> "Model" :
575
619
return Model (self .__dict__ )
576
620
577
- def __new__ (cls , * args : typing .Any , ** kwargs : typing .Any ) -> Self : # pylint: disable=unused-argument
621
+ def __new__ (cls , * args : typing .Any , ** kwargs : typing .Any ) -> Self :
578
622
if f"{ cls .__module__ } .{ cls .__qualname__ } " not in cls ._calculated :
579
623
# we know the last nine classes in mro are going to be 'Model', '_MyMutableMapping', 'MutableMapping',
580
624
# 'Mapping', 'Collection', 'Sized', 'Iterable', 'Container' and 'object'
@@ -585,8 +629,8 @@ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self: # pylint: di
585
629
annotations = {
586
630
k : v
587
631
for mro_class in mros
588
- if hasattr (mro_class , "__annotations__" ) # pylint: disable=no-member
589
- for k , v in mro_class .__annotations__ .items () # pylint: disable=no-member
632
+ if hasattr (mro_class , "__annotations__" )
633
+ for k , v in mro_class .__annotations__ .items ()
590
634
}
591
635
for attr , rf in attr_to_rest_field .items ():
592
636
rf ._module = cls .__module__
@@ -597,12 +641,12 @@ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self: # pylint: di
597
641
cls ._attr_to_rest_field : typing .Dict [str , _RestField ] = dict (attr_to_rest_field .items ())
598
642
cls ._calculated .add (f"{ cls .__module__ } .{ cls .__qualname__ } " )
599
643
600
- return super ().__new__ (cls ) # pylint: disable=no-value-for-parameter
644
+ return super ().__new__ (cls )
601
645
602
646
def __init_subclass__ (cls , discriminator : typing .Optional [str ] = None ) -> None :
603
647
for base in cls .__bases__ :
604
- if hasattr (base , "__mapping__" ): # pylint: disable=no-member
605
- base .__mapping__ [discriminator or cls .__name__ ] = cls # type: ignore # pylint: disable=no-member
648
+ if hasattr (base , "__mapping__" ):
649
+ base .__mapping__ [discriminator or cls .__name__ ] = cls # type: ignore
606
650
607
651
@classmethod
608
652
def _get_discriminator (cls , exist_discriminators ) -> typing .Optional ["_RestField" ]:
@@ -613,7 +657,7 @@ def _get_discriminator(cls, exist_discriminators) -> typing.Optional["_RestField
613
657
614
658
@classmethod
615
659
def _deserialize (cls , data , exist_discriminators ):
616
- if not hasattr (cls , "__mapping__" ): # pylint: disable=no-member
660
+ if not hasattr (cls , "__mapping__" ):
617
661
return cls (data )
618
662
discriminator = cls ._get_discriminator (exist_discriminators )
619
663
if discriminator is None :
@@ -754,7 +798,7 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
754
798
except AttributeError :
755
799
model_name = annotation
756
800
if module is not None :
757
- annotation = _get_model (module , model_name )
801
+ annotation = _get_model (module , model_name ) # type: ignore
758
802
759
803
try :
760
804
if module and _is_model (annotation ):
@@ -894,6 +938,35 @@ def _deserialize(
894
938
return _deserialize_with_callable (deserializer , value )
895
939
896
940
941
+ def _failsafe_deserialize (
942
+ deserializer : typing .Any ,
943
+ value : typing .Any ,
944
+ module : typing .Optional [str ] = None ,
945
+ rf : typing .Optional ["_RestField" ] = None ,
946
+ format : typing .Optional [str ] = None ,
947
+ ) -> typing .Any :
948
+ try :
949
+ return _deserialize (deserializer , value , module , rf , format )
950
+ except DeserializationError :
951
+ _LOGGER .warning (
952
+ "Ran into a deserialization error. Ignoring since this is failsafe deserialization" , exc_info = True
953
+ )
954
+ return None
955
+
956
+
957
+ def _failsafe_deserialize_xml (
958
+ deserializer : typing .Any ,
959
+ value : typing .Any ,
960
+ ) -> typing .Any :
961
+ try :
962
+ return _deserialize_xml (deserializer , value )
963
+ except DeserializationError :
964
+ _LOGGER .warning (
965
+ "Ran into a deserialization error. Ignoring since this is failsafe deserialization" , exc_info = True
966
+ )
967
+ return None
968
+
969
+
897
970
class _RestField :
898
971
def __init__ (
899
972
self ,
0 commit comments