azure-quantum 3.5.1.dev1__py3-none-any.whl → 3.6.0__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.
- azure/quantum/_client/__init__.py +2 -2
- azure/quantum/_client/_client.py +18 -57
- azure/quantum/_client/_configuration.py +13 -22
- azure/quantum/_client/_patch.py +7 -6
- azure/quantum/_client/_utils/__init__.py +6 -0
- azure/quantum/_client/{_model_base.py → _utils/model_base.py} +210 -45
- azure/quantum/_client/{_serialization.py → _utils/serialization.py} +74 -151
- azure/quantum/_client/_validation.py +66 -0
- azure/quantum/_client/_version.py +1 -1
- azure/quantum/_client/aio/__init__.py +29 -0
- azure/quantum/_client/aio/_client.py +110 -0
- azure/quantum/_client/aio/_configuration.py +75 -0
- azure/quantum/_client/aio/_patch.py +21 -0
- azure/quantum/_client/aio/operations/__init__.py +25 -0
- azure/quantum/_client/aio/operations/_operations.py +1988 -0
- azure/quantum/_client/aio/operations/_patch.py +21 -0
- azure/quantum/_client/models/__init__.py +8 -4
- azure/quantum/_client/models/_enums.py +28 -23
- azure/quantum/_client/models/_models.py +198 -106
- azure/quantum/_client/models/_patch.py +7 -6
- azure/quantum/_client/operations/__init__.py +2 -12
- azure/quantum/_client/operations/_operations.py +900 -715
- azure/quantum/_client/operations/_patch.py +7 -6
- azure/quantum/_constants.py +5 -0
- azure/quantum/_mgmt_client.py +18 -8
- azure/quantum/_workspace_connection_params.py +27 -2
- azure/quantum/job/base_job.py +8 -0
- azure/quantum/job/job.py +1 -1
- azure/quantum/job/session.py +11 -0
- azure/quantum/target/target.py +5 -1
- azure/quantum/target/target_factory.py +14 -7
- azure/quantum/version.py +1 -1
- azure/quantum/workspace.py +35 -31
- {azure_quantum-3.5.1.dev1.dist-info → azure_quantum-3.6.0.dist-info}/METADATA +1 -1
- azure_quantum-3.6.0.dist-info/RECORD +74 -0
- azure_quantum-3.5.1.dev1.dist-info/RECORD +0 -65
- {azure_quantum-3.5.1.dev1.dist-info → azure_quantum-3.6.0.dist-info}/WHEEL +0 -0
- {azure_quantum-3.5.1.dev1.dist-info → azure_quantum-3.6.0.dist-info}/top_level.txt +0 -0
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
# pylint: disable=too-many-lines
|
|
1
|
+
# pylint: disable=line-too-long,useless-suppression,too-many-lines
|
|
2
|
+
# coding=utf-8
|
|
2
3
|
# --------------------------------------------------------------------------
|
|
3
|
-
#
|
|
4
4
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
# of this software and associated documentation files (the ""Software""), to
|
|
10
|
-
# deal in the Software without restriction, including without limitation the
|
|
11
|
-
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
12
|
-
# sell copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
# furnished to do so, subject to the following conditions:
|
|
14
|
-
#
|
|
15
|
-
# The above copyright notice and this permission notice shall be included in
|
|
16
|
-
# all copies or substantial portions of the Software.
|
|
17
|
-
#
|
|
18
|
-
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
|
-
# IN THE SOFTWARE.
|
|
25
|
-
#
|
|
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.
|
|
26
8
|
# --------------------------------------------------------------------------
|
|
27
9
|
|
|
28
10
|
# pyright: reportUnnecessaryTypeIgnoreComment=false
|
|
@@ -39,7 +21,6 @@ import re
|
|
|
39
21
|
import sys
|
|
40
22
|
import codecs
|
|
41
23
|
from typing import (
|
|
42
|
-
Dict,
|
|
43
24
|
Any,
|
|
44
25
|
cast,
|
|
45
26
|
Optional,
|
|
@@ -48,10 +29,7 @@ from typing import (
|
|
|
48
29
|
IO,
|
|
49
30
|
Mapping,
|
|
50
31
|
Callable,
|
|
51
|
-
TypeVar,
|
|
52
32
|
MutableMapping,
|
|
53
|
-
Type,
|
|
54
|
-
List,
|
|
55
33
|
)
|
|
56
34
|
|
|
57
35
|
try:
|
|
@@ -61,13 +39,13 @@ except ImportError:
|
|
|
61
39
|
import xml.etree.ElementTree as ET
|
|
62
40
|
|
|
63
41
|
import isodate # type: ignore
|
|
42
|
+
from typing_extensions import Self
|
|
64
43
|
|
|
65
44
|
from azure.core.exceptions import DeserializationError, SerializationError
|
|
66
45
|
from azure.core.serialization import NULL as CoreNull
|
|
67
46
|
|
|
68
47
|
_BOM = codecs.BOM_UTF8.decode(encoding="utf-8")
|
|
69
48
|
|
|
70
|
-
ModelType = TypeVar("ModelType", bound="Model")
|
|
71
49
|
JSON = MutableMapping[str, Any]
|
|
72
50
|
|
|
73
51
|
|
|
@@ -185,73 +163,7 @@ try:
|
|
|
185
163
|
except NameError:
|
|
186
164
|
_long_type = int
|
|
187
165
|
|
|
188
|
-
|
|
189
|
-
class UTC(datetime.tzinfo):
|
|
190
|
-
"""Time Zone info for handling UTC"""
|
|
191
|
-
|
|
192
|
-
def utcoffset(self, dt):
|
|
193
|
-
"""UTF offset for UTC is 0.
|
|
194
|
-
|
|
195
|
-
:param datetime.datetime dt: The datetime
|
|
196
|
-
:returns: The offset
|
|
197
|
-
:rtype: datetime.timedelta
|
|
198
|
-
"""
|
|
199
|
-
return datetime.timedelta(0)
|
|
200
|
-
|
|
201
|
-
def tzname(self, dt):
|
|
202
|
-
"""Timestamp representation.
|
|
203
|
-
|
|
204
|
-
:param datetime.datetime dt: The datetime
|
|
205
|
-
:returns: The timestamp representation
|
|
206
|
-
:rtype: str
|
|
207
|
-
"""
|
|
208
|
-
return "Z"
|
|
209
|
-
|
|
210
|
-
def dst(self, dt):
|
|
211
|
-
"""No daylight saving for UTC.
|
|
212
|
-
|
|
213
|
-
:param datetime.datetime dt: The datetime
|
|
214
|
-
:returns: The daylight saving time
|
|
215
|
-
:rtype: datetime.timedelta
|
|
216
|
-
"""
|
|
217
|
-
return datetime.timedelta(hours=1)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
try:
|
|
221
|
-
from datetime import timezone as _FixedOffset # type: ignore
|
|
222
|
-
except ImportError: # Python 2.7
|
|
223
|
-
|
|
224
|
-
class _FixedOffset(datetime.tzinfo): # type: ignore
|
|
225
|
-
"""Fixed offset in minutes east from UTC.
|
|
226
|
-
Copy/pasted from Python doc
|
|
227
|
-
:param datetime.timedelta offset: offset in timedelta format
|
|
228
|
-
"""
|
|
229
|
-
|
|
230
|
-
def __init__(self, offset) -> None:
|
|
231
|
-
self.__offset = offset
|
|
232
|
-
|
|
233
|
-
def utcoffset(self, dt):
|
|
234
|
-
return self.__offset
|
|
235
|
-
|
|
236
|
-
def tzname(self, dt):
|
|
237
|
-
return str(self.__offset.total_seconds() / 3600)
|
|
238
|
-
|
|
239
|
-
def __repr__(self):
|
|
240
|
-
return "<FixedOffset {}>".format(self.tzname(None))
|
|
241
|
-
|
|
242
|
-
def dst(self, dt):
|
|
243
|
-
return datetime.timedelta(0)
|
|
244
|
-
|
|
245
|
-
def __getinitargs__(self):
|
|
246
|
-
return (self.__offset,)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
try:
|
|
250
|
-
from datetime import timezone
|
|
251
|
-
|
|
252
|
-
TZ_UTC = timezone.utc
|
|
253
|
-
except ImportError:
|
|
254
|
-
TZ_UTC = UTC() # type: ignore
|
|
166
|
+
TZ_UTC = datetime.timezone.utc
|
|
255
167
|
|
|
256
168
|
_FLATTEN = re.compile(r"(?<!\\)\.")
|
|
257
169
|
|
|
@@ -310,17 +222,17 @@ def _create_xml_node(tag, prefix=None, ns=None):
|
|
|
310
222
|
return ET.Element(tag)
|
|
311
223
|
|
|
312
224
|
|
|
313
|
-
class Model
|
|
225
|
+
class Model:
|
|
314
226
|
"""Mixin for all client request body/response body models to support
|
|
315
227
|
serialization and deserialization.
|
|
316
228
|
"""
|
|
317
229
|
|
|
318
|
-
_subtype_map:
|
|
319
|
-
_attribute_map:
|
|
320
|
-
_validation:
|
|
230
|
+
_subtype_map: dict[str, dict[str, Any]] = {}
|
|
231
|
+
_attribute_map: dict[str, dict[str, Any]] = {}
|
|
232
|
+
_validation: dict[str, dict[str, Any]] = {}
|
|
321
233
|
|
|
322
234
|
def __init__(self, **kwargs: Any) -> None:
|
|
323
|
-
self.additional_properties: Optional[
|
|
235
|
+
self.additional_properties: Optional[dict[str, Any]] = {}
|
|
324
236
|
for k in kwargs: # pylint: disable=consider-using-dict-items
|
|
325
237
|
if k not in self._attribute_map:
|
|
326
238
|
_LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__)
|
|
@@ -397,7 +309,7 @@ class Model(object):
|
|
|
397
309
|
def as_dict(
|
|
398
310
|
self,
|
|
399
311
|
keep_readonly: bool = True,
|
|
400
|
-
key_transformer: Callable[[str,
|
|
312
|
+
key_transformer: Callable[[str, dict[str, Any], Any], Any] = attribute_transformer,
|
|
401
313
|
**kwargs: Any
|
|
402
314
|
) -> JSON:
|
|
403
315
|
"""Return a dict that can be serialized using json.dump.
|
|
@@ -450,25 +362,25 @@ class Model(object):
|
|
|
450
362
|
return client_models
|
|
451
363
|
|
|
452
364
|
@classmethod
|
|
453
|
-
def deserialize(cls
|
|
365
|
+
def deserialize(cls, data: Any, content_type: Optional[str] = None) -> Self:
|
|
454
366
|
"""Parse a str using the RestAPI syntax and return a model.
|
|
455
367
|
|
|
456
368
|
:param str data: A str using RestAPI structure. JSON by default.
|
|
457
369
|
:param str content_type: JSON by default, set application/xml if XML.
|
|
458
370
|
:returns: An instance of this model
|
|
459
|
-
:raises
|
|
460
|
-
:rtype:
|
|
371
|
+
:raises DeserializationError: if something went wrong
|
|
372
|
+
:rtype: Self
|
|
461
373
|
"""
|
|
462
374
|
deserializer = Deserializer(cls._infer_class_models())
|
|
463
375
|
return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
|
|
464
376
|
|
|
465
377
|
@classmethod
|
|
466
378
|
def from_dict(
|
|
467
|
-
cls
|
|
379
|
+
cls,
|
|
468
380
|
data: Any,
|
|
469
|
-
key_extractors: Optional[Callable[[str,
|
|
381
|
+
key_extractors: Optional[Callable[[str, dict[str, Any], Any], Any]] = None,
|
|
470
382
|
content_type: Optional[str] = None,
|
|
471
|
-
) ->
|
|
383
|
+
) -> Self:
|
|
472
384
|
"""Parse a dict using given key extractor return a model.
|
|
473
385
|
|
|
474
386
|
By default consider key
|
|
@@ -479,8 +391,8 @@ class Model(object):
|
|
|
479
391
|
:param function key_extractors: A key extractor function.
|
|
480
392
|
:param str content_type: JSON by default, set application/xml if XML.
|
|
481
393
|
:returns: An instance of this model
|
|
482
|
-
:raises
|
|
483
|
-
:rtype:
|
|
394
|
+
:raises DeserializationError: if something went wrong
|
|
395
|
+
:rtype: Self
|
|
484
396
|
"""
|
|
485
397
|
deserializer = Deserializer(cls._infer_class_models())
|
|
486
398
|
deserializer.key_extractors = ( # type: ignore
|
|
@@ -500,7 +412,7 @@ class Model(object):
|
|
|
500
412
|
return {}
|
|
501
413
|
result = dict(cls._subtype_map[key])
|
|
502
414
|
for valuetype in cls._subtype_map[key].values():
|
|
503
|
-
result
|
|
415
|
+
result |= objects[valuetype]._flatten_subtype(key, objects) # pylint: disable=protected-access
|
|
504
416
|
return result
|
|
505
417
|
|
|
506
418
|
@classmethod
|
|
@@ -563,7 +475,7 @@ def _decode_attribute_map_key(key):
|
|
|
563
475
|
return key.replace("\\.", ".")
|
|
564
476
|
|
|
565
477
|
|
|
566
|
-
class Serializer
|
|
478
|
+
class Serializer: # pylint: disable=too-many-public-methods
|
|
567
479
|
"""Request object model serializer."""
|
|
568
480
|
|
|
569
481
|
basic_types = {str: "str", int: "int", bool: "bool", float: "float"}
|
|
@@ -614,7 +526,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
614
526
|
"[]": self.serialize_iter,
|
|
615
527
|
"{}": self.serialize_dict,
|
|
616
528
|
}
|
|
617
|
-
self.dependencies:
|
|
529
|
+
self.dependencies: dict[str, type] = dict(classes) if classes else {}
|
|
618
530
|
self.key_transformer = full_restapi_key_transformer
|
|
619
531
|
self.client_side_validation = True
|
|
620
532
|
|
|
@@ -626,7 +538,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
626
538
|
:param object target_obj: The data to be serialized.
|
|
627
539
|
:param str data_type: The type to be serialized from.
|
|
628
540
|
:rtype: str, dict
|
|
629
|
-
:raises
|
|
541
|
+
:raises SerializationError: if serialization fails.
|
|
630
542
|
:returns: The serialized data.
|
|
631
543
|
"""
|
|
632
544
|
key_transformer = kwargs.get("key_transformer", self.key_transformer)
|
|
@@ -665,7 +577,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
665
577
|
|
|
666
578
|
if attr_name == "additional_properties" and attr_desc["key"] == "":
|
|
667
579
|
if target_obj.additional_properties is not None:
|
|
668
|
-
serialized
|
|
580
|
+
serialized |= target_obj.additional_properties
|
|
669
581
|
continue
|
|
670
582
|
try:
|
|
671
583
|
|
|
@@ -736,8 +648,8 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
736
648
|
:param object data: The data to be serialized.
|
|
737
649
|
:param str data_type: The type to be serialized from.
|
|
738
650
|
:rtype: dict
|
|
739
|
-
:raises
|
|
740
|
-
:raises
|
|
651
|
+
:raises SerializationError: if serialization fails.
|
|
652
|
+
:raises ValueError: if data is None
|
|
741
653
|
:returns: The serialized request body
|
|
742
654
|
"""
|
|
743
655
|
|
|
@@ -781,8 +693,8 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
781
693
|
:param str data_type: The type to be serialized from.
|
|
782
694
|
:rtype: str
|
|
783
695
|
:returns: The serialized URL path
|
|
784
|
-
:raises
|
|
785
|
-
:raises
|
|
696
|
+
:raises TypeError: if serialization fails.
|
|
697
|
+
:raises ValueError: if data is None
|
|
786
698
|
"""
|
|
787
699
|
try:
|
|
788
700
|
output = self.serialize_data(data, data_type, **kwargs)
|
|
@@ -805,8 +717,8 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
805
717
|
:param object data: The data to be serialized.
|
|
806
718
|
:param str data_type: The type to be serialized from.
|
|
807
719
|
:rtype: str, list
|
|
808
|
-
:raises
|
|
809
|
-
:raises
|
|
720
|
+
:raises TypeError: if serialization fails.
|
|
721
|
+
:raises ValueError: if data is None
|
|
810
722
|
:returns: The serialized query parameter
|
|
811
723
|
"""
|
|
812
724
|
try:
|
|
@@ -835,8 +747,8 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
835
747
|
:param object data: The data to be serialized.
|
|
836
748
|
:param str data_type: The type to be serialized from.
|
|
837
749
|
:rtype: str
|
|
838
|
-
:raises
|
|
839
|
-
:raises
|
|
750
|
+
:raises TypeError: if serialization fails.
|
|
751
|
+
:raises ValueError: if data is None
|
|
840
752
|
:returns: The serialized header
|
|
841
753
|
"""
|
|
842
754
|
try:
|
|
@@ -855,9 +767,9 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
855
767
|
|
|
856
768
|
:param object data: The data to be serialized.
|
|
857
769
|
:param str data_type: The type to be serialized from.
|
|
858
|
-
:raises
|
|
859
|
-
:raises
|
|
860
|
-
:raises
|
|
770
|
+
:raises AttributeError: if required data is None.
|
|
771
|
+
:raises ValueError: if data is None
|
|
772
|
+
:raises SerializationError: if serialization fails.
|
|
861
773
|
:returns: The serialized data.
|
|
862
774
|
:rtype: str, int, float, bool, dict, list
|
|
863
775
|
"""
|
|
@@ -875,7 +787,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
875
787
|
|
|
876
788
|
# If dependencies is empty, try with current data class
|
|
877
789
|
# It has to be a subclass of Enum anyway
|
|
878
|
-
enum_type = self.dependencies.get(data_type, data.__class__)
|
|
790
|
+
enum_type = self.dependencies.get(data_type, cast(type, data.__class__))
|
|
879
791
|
if issubclass(enum_type, Enum):
|
|
880
792
|
return Serializer.serialize_enum(data, enum_obj=enum_type)
|
|
881
793
|
|
|
@@ -909,13 +821,20 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
909
821
|
:param str data_type: Type of object in the iterable.
|
|
910
822
|
:rtype: str, int, float, bool
|
|
911
823
|
:return: serialized object
|
|
824
|
+
:raises TypeError: raise if data_type is not one of str, int, float, bool.
|
|
912
825
|
"""
|
|
913
826
|
custom_serializer = cls._get_custom_serializers(data_type, **kwargs)
|
|
914
827
|
if custom_serializer:
|
|
915
828
|
return custom_serializer(data)
|
|
916
829
|
if data_type == "str":
|
|
917
830
|
return cls.serialize_unicode(data)
|
|
918
|
-
|
|
831
|
+
if data_type == "int":
|
|
832
|
+
return int(data)
|
|
833
|
+
if data_type == "float":
|
|
834
|
+
return float(data)
|
|
835
|
+
if data_type == "bool":
|
|
836
|
+
return bool(data)
|
|
837
|
+
raise TypeError("Unknown basic data type: {}".format(data_type))
|
|
919
838
|
|
|
920
839
|
@classmethod
|
|
921
840
|
def serialize_unicode(cls, data):
|
|
@@ -1192,7 +1111,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
1192
1111
|
|
|
1193
1112
|
:param Datetime attr: Object to be serialized.
|
|
1194
1113
|
:rtype: str
|
|
1195
|
-
:raises
|
|
1114
|
+
:raises TypeError: if format invalid.
|
|
1196
1115
|
:return: serialized rfc
|
|
1197
1116
|
"""
|
|
1198
1117
|
try:
|
|
@@ -1218,7 +1137,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
1218
1137
|
|
|
1219
1138
|
:param Datetime attr: Object to be serialized.
|
|
1220
1139
|
:rtype: str
|
|
1221
|
-
:raises
|
|
1140
|
+
:raises SerializationError: if format invalid.
|
|
1222
1141
|
:return: serialized iso
|
|
1223
1142
|
"""
|
|
1224
1143
|
if isinstance(attr, str):
|
|
@@ -1251,7 +1170,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
|
|
|
1251
1170
|
|
|
1252
1171
|
:param Datetime attr: Object to be serialized.
|
|
1253
1172
|
:rtype: int
|
|
1254
|
-
:raises
|
|
1173
|
+
:raises SerializationError: if format invalid
|
|
1255
1174
|
:return: serialied unix
|
|
1256
1175
|
"""
|
|
1257
1176
|
if isinstance(attr, int):
|
|
@@ -1270,7 +1189,7 @@ def rest_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argumen
|
|
|
1270
1189
|
|
|
1271
1190
|
while "." in key:
|
|
1272
1191
|
# Need the cast, as for some reasons "split" is typed as list[str | Any]
|
|
1273
|
-
dict_keys = cast(
|
|
1192
|
+
dict_keys = cast(list[str], _FLATTEN.split(key))
|
|
1274
1193
|
if len(dict_keys) == 1:
|
|
1275
1194
|
key = _decode_attribute_map_key(dict_keys[0])
|
|
1276
1195
|
break
|
|
@@ -1429,7 +1348,7 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument
|
|
|
1429
1348
|
# Iter and wrapped, should have found one node only (the wrap one)
|
|
1430
1349
|
if len(children) != 1:
|
|
1431
1350
|
raise DeserializationError(
|
|
1432
|
-
"Tried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?".format(
|
|
1351
|
+
"Tried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?".format(
|
|
1433
1352
|
xml_name
|
|
1434
1353
|
)
|
|
1435
1354
|
)
|
|
@@ -1441,7 +1360,7 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument
|
|
|
1441
1360
|
return children[0]
|
|
1442
1361
|
|
|
1443
1362
|
|
|
1444
|
-
class Deserializer
|
|
1363
|
+
class Deserializer:
|
|
1445
1364
|
"""Response object model deserializer.
|
|
1446
1365
|
|
|
1447
1366
|
:param dict classes: Class type dictionary for deserializing complex types.
|
|
@@ -1472,7 +1391,7 @@ class Deserializer(object):
|
|
|
1472
1391
|
"duration": (isodate.Duration, datetime.timedelta),
|
|
1473
1392
|
"iso-8601": (datetime.datetime),
|
|
1474
1393
|
}
|
|
1475
|
-
self.dependencies:
|
|
1394
|
+
self.dependencies: dict[str, type] = dict(classes) if classes else {}
|
|
1476
1395
|
self.key_extractors = [rest_key_extractor, xml_key_extractor]
|
|
1477
1396
|
# Additional properties only works if the "rest_key_extractor" is used to
|
|
1478
1397
|
# extract the keys. Making it to work whatever the key extractor is too much
|
|
@@ -1488,7 +1407,7 @@ class Deserializer(object):
|
|
|
1488
1407
|
:param str target_obj: Target data type to deserialize to.
|
|
1489
1408
|
:param requests.Response response_data: REST response object.
|
|
1490
1409
|
:param str content_type: Swagger "produces" if available.
|
|
1491
|
-
:raises
|
|
1410
|
+
:raises DeserializationError: if deserialization fails.
|
|
1492
1411
|
:return: Deserialized object.
|
|
1493
1412
|
:rtype: object
|
|
1494
1413
|
"""
|
|
@@ -1502,7 +1421,7 @@ class Deserializer(object):
|
|
|
1502
1421
|
|
|
1503
1422
|
:param str target_obj: Target data type to deserialize to.
|
|
1504
1423
|
:param object data: Object to deserialize.
|
|
1505
|
-
:raises
|
|
1424
|
+
:raises DeserializationError: if deserialization fails.
|
|
1506
1425
|
:return: Deserialized object.
|
|
1507
1426
|
:rtype: object
|
|
1508
1427
|
"""
|
|
@@ -1717,7 +1636,7 @@ class Deserializer(object):
|
|
|
1717
1636
|
|
|
1718
1637
|
:param str data: The response string to be deserialized.
|
|
1719
1638
|
:param str data_type: The type to deserialize to.
|
|
1720
|
-
:raises
|
|
1639
|
+
:raises DeserializationError: if deserialization fails.
|
|
1721
1640
|
:return: Deserialized object.
|
|
1722
1641
|
:rtype: object
|
|
1723
1642
|
"""
|
|
@@ -1799,7 +1718,7 @@ class Deserializer(object):
|
|
|
1799
1718
|
:param dict attr: Dictionary to be deserialized.
|
|
1800
1719
|
:return: Deserialized object.
|
|
1801
1720
|
:rtype: dict
|
|
1802
|
-
:raises
|
|
1721
|
+
:raises TypeError: if non-builtin datatype encountered.
|
|
1803
1722
|
"""
|
|
1804
1723
|
if attr is None:
|
|
1805
1724
|
return None
|
|
@@ -1845,7 +1764,7 @@ class Deserializer(object):
|
|
|
1845
1764
|
:param str data_type: deserialization data type.
|
|
1846
1765
|
:return: Deserialized basic type.
|
|
1847
1766
|
:rtype: str, int, float or bool
|
|
1848
|
-
:raises
|
|
1767
|
+
:raises TypeError: if string format is not valid or data_type is not one of str, int, float, bool.
|
|
1849
1768
|
"""
|
|
1850
1769
|
# If we're here, data is supposed to be a basic type.
|
|
1851
1770
|
# If it's still an XML node, take the text
|
|
@@ -1871,7 +1790,11 @@ class Deserializer(object):
|
|
|
1871
1790
|
|
|
1872
1791
|
if data_type == "str":
|
|
1873
1792
|
return self.deserialize_unicode(attr)
|
|
1874
|
-
|
|
1793
|
+
if data_type == "int":
|
|
1794
|
+
return int(attr)
|
|
1795
|
+
if data_type == "float":
|
|
1796
|
+
return float(attr)
|
|
1797
|
+
raise TypeError("Unknown basic data type: {}".format(data_type))
|
|
1875
1798
|
|
|
1876
1799
|
@staticmethod
|
|
1877
1800
|
def deserialize_unicode(data):
|
|
@@ -1936,7 +1859,7 @@ class Deserializer(object):
|
|
|
1936
1859
|
:param str attr: response string to be deserialized.
|
|
1937
1860
|
:return: Deserialized bytearray
|
|
1938
1861
|
:rtype: bytearray
|
|
1939
|
-
:raises
|
|
1862
|
+
:raises TypeError: if string format invalid.
|
|
1940
1863
|
"""
|
|
1941
1864
|
if isinstance(attr, ET.Element):
|
|
1942
1865
|
attr = attr.text
|
|
@@ -1949,7 +1872,7 @@ class Deserializer(object):
|
|
|
1949
1872
|
:param str attr: response string to be deserialized.
|
|
1950
1873
|
:return: Deserialized base64 string
|
|
1951
1874
|
:rtype: bytearray
|
|
1952
|
-
:raises
|
|
1875
|
+
:raises TypeError: if string format invalid.
|
|
1953
1876
|
"""
|
|
1954
1877
|
if isinstance(attr, ET.Element):
|
|
1955
1878
|
attr = attr.text
|
|
@@ -1964,7 +1887,7 @@ class Deserializer(object):
|
|
|
1964
1887
|
|
|
1965
1888
|
:param str attr: response string to be deserialized.
|
|
1966
1889
|
:return: Deserialized decimal
|
|
1967
|
-
:raises
|
|
1890
|
+
:raises DeserializationError: if string format invalid.
|
|
1968
1891
|
:rtype: decimal
|
|
1969
1892
|
"""
|
|
1970
1893
|
if isinstance(attr, ET.Element):
|
|
@@ -1982,7 +1905,7 @@ class Deserializer(object):
|
|
|
1982
1905
|
:param str attr: response string to be deserialized.
|
|
1983
1906
|
:return: Deserialized int
|
|
1984
1907
|
:rtype: long or int
|
|
1985
|
-
:raises
|
|
1908
|
+
:raises ValueError: if string format invalid.
|
|
1986
1909
|
"""
|
|
1987
1910
|
if isinstance(attr, ET.Element):
|
|
1988
1911
|
attr = attr.text
|
|
@@ -1995,7 +1918,7 @@ class Deserializer(object):
|
|
|
1995
1918
|
:param str attr: response string to be deserialized.
|
|
1996
1919
|
:return: Deserialized duration
|
|
1997
1920
|
:rtype: TimeDelta
|
|
1998
|
-
:raises
|
|
1921
|
+
:raises DeserializationError: if string format invalid.
|
|
1999
1922
|
"""
|
|
2000
1923
|
if isinstance(attr, ET.Element):
|
|
2001
1924
|
attr = attr.text
|
|
@@ -2013,7 +1936,7 @@ class Deserializer(object):
|
|
|
2013
1936
|
:param str attr: response string to be deserialized.
|
|
2014
1937
|
:return: Deserialized date
|
|
2015
1938
|
:rtype: Date
|
|
2016
|
-
:raises
|
|
1939
|
+
:raises DeserializationError: if string format invalid.
|
|
2017
1940
|
"""
|
|
2018
1941
|
if isinstance(attr, ET.Element):
|
|
2019
1942
|
attr = attr.text
|
|
@@ -2029,7 +1952,7 @@ class Deserializer(object):
|
|
|
2029
1952
|
:param str attr: response string to be deserialized.
|
|
2030
1953
|
:return: Deserialized time
|
|
2031
1954
|
:rtype: datetime.time
|
|
2032
|
-
:raises
|
|
1955
|
+
:raises DeserializationError: if string format invalid.
|
|
2033
1956
|
"""
|
|
2034
1957
|
if isinstance(attr, ET.Element):
|
|
2035
1958
|
attr = attr.text
|
|
@@ -2044,14 +1967,14 @@ class Deserializer(object):
|
|
|
2044
1967
|
:param str attr: response string to be deserialized.
|
|
2045
1968
|
:return: Deserialized RFC datetime
|
|
2046
1969
|
:rtype: Datetime
|
|
2047
|
-
:raises
|
|
1970
|
+
:raises DeserializationError: if string format invalid.
|
|
2048
1971
|
"""
|
|
2049
1972
|
if isinstance(attr, ET.Element):
|
|
2050
1973
|
attr = attr.text
|
|
2051
1974
|
try:
|
|
2052
1975
|
parsed_date = email.utils.parsedate_tz(attr) # type: ignore
|
|
2053
1976
|
date_obj = datetime.datetime(
|
|
2054
|
-
*parsed_date[:6], tzinfo=
|
|
1977
|
+
*parsed_date[:6], tzinfo=datetime.timezone(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60))
|
|
2055
1978
|
)
|
|
2056
1979
|
if not date_obj.tzinfo:
|
|
2057
1980
|
date_obj = date_obj.astimezone(tz=TZ_UTC)
|
|
@@ -2067,7 +1990,7 @@ class Deserializer(object):
|
|
|
2067
1990
|
:param str attr: response string to be deserialized.
|
|
2068
1991
|
:return: Deserialized ISO datetime
|
|
2069
1992
|
:rtype: Datetime
|
|
2070
|
-
:raises
|
|
1993
|
+
:raises DeserializationError: if string format invalid.
|
|
2071
1994
|
"""
|
|
2072
1995
|
if isinstance(attr, ET.Element):
|
|
2073
1996
|
attr = attr.text
|
|
@@ -2105,7 +2028,7 @@ class Deserializer(object):
|
|
|
2105
2028
|
:param int attr: Object to be serialized.
|
|
2106
2029
|
:return: Deserialized datetime
|
|
2107
2030
|
:rtype: Datetime
|
|
2108
|
-
:raises
|
|
2031
|
+
:raises DeserializationError: if format invalid
|
|
2109
2032
|
"""
|
|
2110
2033
|
if isinstance(attr, ET.Element):
|
|
2111
2034
|
attr = int(attr.text) # type: ignore
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
5
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
6
|
+
# --------------------------------------------------------------------------
|
|
7
|
+
import functools
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def api_version_validation(**kwargs):
|
|
11
|
+
params_added_on = kwargs.pop("params_added_on", {})
|
|
12
|
+
method_added_on = kwargs.pop("method_added_on", "")
|
|
13
|
+
api_versions_list = kwargs.pop("api_versions_list", [])
|
|
14
|
+
|
|
15
|
+
def _index_with_default(value: str, default: int = -1) -> int:
|
|
16
|
+
"""Get the index of value in lst, or return default if not found.
|
|
17
|
+
|
|
18
|
+
:param value: The value to search for in the api_versions_list.
|
|
19
|
+
:type value: str
|
|
20
|
+
:param default: The default value to return if the value is not found.
|
|
21
|
+
:type default: int
|
|
22
|
+
:return: The index of the value in the list, or the default value if not found.
|
|
23
|
+
:rtype: int
|
|
24
|
+
"""
|
|
25
|
+
try:
|
|
26
|
+
return api_versions_list.index(value)
|
|
27
|
+
except ValueError:
|
|
28
|
+
return default
|
|
29
|
+
|
|
30
|
+
def decorator(func):
|
|
31
|
+
@functools.wraps(func)
|
|
32
|
+
def wrapper(*args, **kwargs):
|
|
33
|
+
try:
|
|
34
|
+
# this assumes the client has an _api_version attribute
|
|
35
|
+
client = args[0]
|
|
36
|
+
client_api_version = client._config.api_version # pylint: disable=protected-access
|
|
37
|
+
except AttributeError:
|
|
38
|
+
return func(*args, **kwargs)
|
|
39
|
+
|
|
40
|
+
if _index_with_default(method_added_on) > _index_with_default(client_api_version):
|
|
41
|
+
raise ValueError(
|
|
42
|
+
f"'{func.__name__}' is not available in API version "
|
|
43
|
+
f"{client_api_version}. Pass service API version {method_added_on} or newer to your client."
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
unsupported = {
|
|
47
|
+
parameter: api_version
|
|
48
|
+
for api_version, parameters in params_added_on.items()
|
|
49
|
+
for parameter in parameters
|
|
50
|
+
if parameter in kwargs and _index_with_default(api_version) > _index_with_default(client_api_version)
|
|
51
|
+
}
|
|
52
|
+
if unsupported:
|
|
53
|
+
raise ValueError(
|
|
54
|
+
"".join(
|
|
55
|
+
[
|
|
56
|
+
f"'{param}' is not available in API version {client_api_version}. "
|
|
57
|
+
f"Use service API version {version} or newer.\n"
|
|
58
|
+
for param, version in unsupported.items()
|
|
59
|
+
]
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
return func(*args, **kwargs)
|
|
63
|
+
|
|
64
|
+
return wrapper
|
|
65
|
+
|
|
66
|
+
return decorator
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# --------------------------------------------------------------------------
|
|
3
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
# Code generated by Microsoft (R) Python Code Generator.
|
|
6
|
+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
# pylint: disable=wrong-import-position
|
|
9
|
+
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ._patch import * # pylint: disable=unused-wildcard-import
|
|
14
|
+
|
|
15
|
+
from ._client import WorkspaceClient # type: ignore
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
from ._patch import __all__ as _patch_all
|
|
19
|
+
from ._patch import *
|
|
20
|
+
except ImportError:
|
|
21
|
+
_patch_all = []
|
|
22
|
+
from ._patch import patch_sdk as _patch_sdk
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"WorkspaceClient",
|
|
26
|
+
]
|
|
27
|
+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
|
|
28
|
+
|
|
29
|
+
_patch_sdk()
|