diracx-client 0.0.1a11__py3-none-any.whl → 0.0.1a13__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
diracx/client/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # coding=utf-8
2
2
  # --------------------------------------------------------------------------
3
- # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.1, generator: @autorest/python@6.4.11)
3
+ # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.9)
4
4
  # Changes may cause incorrect behavior and will be lost if the code is regenerated.
5
5
  # --------------------------------------------------------------------------
6
6
 
diracx/client/_client.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # coding=utf-8
2
2
  # --------------------------------------------------------------------------
3
- # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.1, generator: @autorest/python@6.4.11)
3
+ # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.9)
4
4
  # Changes may cause incorrect behavior and will be lost if the code is regenerated.
5
5
  # --------------------------------------------------------------------------
6
6
 
@@ -8,6 +8,7 @@ from copy import deepcopy
8
8
  from typing import Any
9
9
 
10
10
  from azure.core import PipelineClient
11
+ from azure.core.pipeline import policies
11
12
  from azure.core.rest import HttpRequest, HttpResponse
12
13
 
13
14
  from . import models as _models
@@ -40,8 +41,29 @@ class Dirac: # pylint: disable=client-accepts-api-version-keyword
40
41
  self, *, endpoint: str = "", **kwargs: Any
41
42
  ) -> None:
42
43
  self._config = DiracConfiguration(**kwargs)
44
+ _policies = kwargs.pop("policies", None)
45
+ if _policies is None:
46
+ _policies = [
47
+ policies.RequestIdPolicy(**kwargs),
48
+ self._config.headers_policy,
49
+ self._config.user_agent_policy,
50
+ self._config.proxy_policy,
51
+ policies.ContentDecodePolicy(**kwargs),
52
+ self._config.redirect_policy,
53
+ self._config.retry_policy,
54
+ self._config.authentication_policy,
55
+ self._config.custom_hook_policy,
56
+ self._config.logging_policy,
57
+ policies.DistributedTracingPolicy(**kwargs),
58
+ (
59
+ policies.SensitiveHeaderCleanupPolicy(**kwargs)
60
+ if self._config.redirect_policy
61
+ else None
62
+ ),
63
+ self._config.http_logging_policy,
64
+ ]
43
65
  self._client: PipelineClient = PipelineClient(
44
- base_url=endpoint, config=self._config, **kwargs
66
+ base_url=endpoint, policies=_policies, **kwargs
45
67
  )
46
68
 
47
69
  client_models = {
@@ -53,7 +75,7 @@ class Dirac: # pylint: disable=client-accepts-api-version-keyword
53
75
  self.well_known = WellKnownOperations(
54
76
  self._client, self._config, self._serialize, self._deserialize
55
77
  )
56
- self.auth = AuthOperations( # pylint: disable=abstract-class-instantiated
78
+ self.auth = AuthOperations(
57
79
  self._client, self._config, self._serialize, self._deserialize
58
80
  )
59
81
  self.config = ConfigOperations(
@@ -63,7 +85,9 @@ class Dirac: # pylint: disable=client-accepts-api-version-keyword
63
85
  self._client, self._config, self._serialize, self._deserialize
64
86
  )
65
87
 
66
- def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
88
+ def send_request(
89
+ self, request: HttpRequest, *, stream: bool = False, **kwargs: Any
90
+ ) -> HttpResponse:
67
91
  """Runs the network request through the client's chained policies.
68
92
 
69
93
  >>> from azure.core.rest import HttpRequest
@@ -83,7 +107,7 @@ class Dirac: # pylint: disable=client-accepts-api-version-keyword
83
107
 
84
108
  request_copy = deepcopy(request)
85
109
  request_copy.url = self._client.format_url(request_copy.url)
86
- return self._client.send_request(request_copy, **kwargs)
110
+ return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
87
111
 
88
112
  def close(self) -> None:
89
113
  self._client.close()
@@ -1,18 +1,17 @@
1
1
  # coding=utf-8
2
2
  # --------------------------------------------------------------------------
3
- # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.1, generator: @autorest/python@6.4.11)
3
+ # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.9)
4
4
  # Changes may cause incorrect behavior and will be lost if the code is regenerated.
5
5
  # --------------------------------------------------------------------------
6
6
 
7
7
  from typing import Any
8
8
 
9
- from azure.core.configuration import Configuration
10
9
  from azure.core.pipeline import policies
11
10
 
12
11
  VERSION = "unknown"
13
12
 
14
13
 
15
- class DiracConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
14
+ class DiracConfiguration: # pylint: disable=too-many-instance-attributes
16
15
  """Configuration for Dirac.
17
16
 
18
17
  Note that all parameters used to create this instance are saved as instance
@@ -20,9 +19,9 @@ class DiracConfiguration(Configuration): # pylint: disable=too-many-instance-at
20
19
  """
21
20
 
22
21
  def __init__(self, **kwargs: Any) -> None:
23
- super(DiracConfiguration, self).__init__(**kwargs)
24
22
 
25
23
  kwargs.setdefault("sdk_moniker", "dirac/{}".format(VERSION))
24
+ self.polling_interval = kwargs.get("polling_interval", 30)
26
25
  self._configure(**kwargs)
27
26
 
28
27
  def _configure(self, **kwargs: Any) -> None:
@@ -39,11 +38,11 @@ class DiracConfiguration(Configuration): # pylint: disable=too-many-instance-at
39
38
  self.http_logging_policy = kwargs.get(
40
39
  "http_logging_policy"
41
40
  ) or policies.HttpLoggingPolicy(**kwargs)
42
- self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
43
41
  self.custom_hook_policy = kwargs.get(
44
42
  "custom_hook_policy"
45
43
  ) or policies.CustomHookPolicy(**kwargs)
46
44
  self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(
47
45
  **kwargs
48
46
  )
47
+ self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
49
48
  self.authentication_policy = kwargs.get("authentication_policy")
@@ -63,12 +63,8 @@ import xml.etree.ElementTree as ET
63
63
 
64
64
  import isodate # type: ignore
65
65
 
66
- from azure.core.exceptions import (
67
- DeserializationError,
68
- SerializationError,
69
- raise_with_traceback,
70
- )
71
- from azure.core.serialization import NULL as AzureCoreNull
66
+ from azure.core.exceptions import DeserializationError, SerializationError
67
+ from azure.core.serialization import NULL as CoreNull
72
68
 
73
69
  _BOM = codecs.BOM_UTF8.decode(encoding="utf-8")
74
70
 
@@ -77,6 +73,7 @@ JSON = MutableMapping[str, Any]
77
73
 
78
74
 
79
75
  class RawDeserializer:
76
+
80
77
  # Accept "text" because we're open minded people...
81
78
  JSON_REGEXP = re.compile(r"^(application|text)/([a-z+.]+\+)?json$")
82
79
 
@@ -120,6 +117,7 @@ class RawDeserializer:
120
117
  raise DeserializationError("JSON is invalid: {}".format(err), err)
121
118
  elif "xml" in (content_type or []):
122
119
  try:
120
+
123
121
  try:
124
122
  if isinstance(data, unicode): # type: ignore
125
123
  # If I'm Python 2.7 and unicode XML will scream if I try a "fromstring" on unicode string
@@ -128,7 +126,7 @@ class RawDeserializer:
128
126
  pass
129
127
 
130
128
  return ET.fromstring(data_as_str) # nosec
131
- except ET.ParseError:
129
+ except ET.ParseError as err:
132
130
  # It might be because the server has an issue, and returned JSON with
133
131
  # content-type XML....
134
132
  # So let's try a JSON load, and if it's still broken
@@ -147,7 +145,7 @@ class RawDeserializer:
147
145
  # The function hack is because Py2.7 messes up with exception
148
146
  # context otherwise.
149
147
  _LOGGER.critical("Wasn't XML not JSON, failing")
150
- raise_with_traceback(DeserializationError, "XML is invalid")
148
+ raise DeserializationError("XML is invalid") from err
151
149
  raise DeserializationError(
152
150
  "Cannot deserialize content-type: {}".format(content_type)
153
151
  )
@@ -178,13 +176,6 @@ class RawDeserializer:
178
176
  return None
179
177
 
180
178
 
181
- try:
182
- basestring # type: ignore
183
- unicode_str = unicode # type: ignore
184
- except NameError:
185
- basestring = str
186
- unicode_str = str
187
-
188
179
  _LOGGER = logging.getLogger(__name__)
189
180
 
190
181
  try:
@@ -303,7 +294,7 @@ class Model(object):
303
294
  _validation: Dict[str, Dict[str, Any]] = {}
304
295
 
305
296
  def __init__(self, **kwargs: Any) -> None:
306
- self.additional_properties: Dict[str, Any] = {}
297
+ self.additional_properties: Optional[Dict[str, Any]] = {}
307
298
  for k in kwargs:
308
299
  if k not in self._attribute_map:
309
300
  _LOGGER.warning(
@@ -360,7 +351,7 @@ class Model(object):
360
351
  )
361
352
 
362
353
  def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
363
- """Return the JSON that would be sent to azure from this model.
354
+ """Return the JSON that would be sent to server from this model.
364
355
 
365
356
  This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`.
366
357
 
@@ -371,7 +362,7 @@ class Model(object):
371
362
  :rtype: dict
372
363
  """
373
364
  serializer = Serializer(self._infer_class_models())
374
- return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs)
365
+ return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore
375
366
 
376
367
  def as_dict(
377
368
  self,
@@ -412,9 +403,7 @@ class Model(object):
412
403
  :rtype: dict
413
404
  """
414
405
  serializer = Serializer(self._infer_class_models())
415
- return serializer._serialize(
416
- self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs
417
- )
406
+ return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore
418
407
 
419
408
  @classmethod
420
409
  def _infer_class_models(cls):
@@ -443,7 +432,7 @@ class Model(object):
443
432
  :raises: DeserializationError if something went wrong
444
433
  """
445
434
  deserializer = Deserializer(cls._infer_class_models())
446
- return deserializer(cls.__name__, data, content_type=content_type)
435
+ return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
447
436
 
448
437
  @classmethod
449
438
  def from_dict(
@@ -473,7 +462,7 @@ class Model(object):
473
462
  if key_extractors is None
474
463
  else key_extractors
475
464
  )
476
- return deserializer(cls.__name__, data, content_type=content_type)
465
+ return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
477
466
 
478
467
  @classmethod
479
468
  def _flatten_subtype(cls, key, objects):
@@ -581,7 +570,7 @@ class Serializer(object):
581
570
  "multiple": lambda x, y: x % y != 0,
582
571
  }
583
572
 
584
- def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
573
+ def __init__(self, classes: Optional[Mapping[str, type]] = None):
585
574
  self.serialize_type = {
586
575
  "iso-8601": Serializer.serialize_iso,
587
576
  "rfc-1123": Serializer.serialize_rfc,
@@ -597,7 +586,7 @@ class Serializer(object):
597
586
  "[]": self.serialize_iter,
598
587
  "{}": self.serialize_dict,
599
588
  }
600
- self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {}
589
+ self.dependencies: Dict[str, type] = dict(classes) if classes else {}
601
590
  self.key_transformer = full_restapi_key_transformer
602
591
  self.client_side_validation = True
603
592
 
@@ -650,6 +639,7 @@ class Serializer(object):
650
639
  serialized.update(target_obj.additional_properties)
651
640
  continue
652
641
  try:
642
+
653
643
  orig_attr = getattr(target_obj, attr)
654
644
  if is_xml_model_serialization:
655
645
  pass # Don't provide "transformer" for XML for now. Keep "orig_attr"
@@ -692,7 +682,7 @@ class Serializer(object):
692
682
  else: # That's a basic type
693
683
  # Integrate namespace if necessary
694
684
  local_node = _create_xml_node(xml_name, xml_prefix, xml_ns)
695
- local_node.text = unicode_str(new_attr)
685
+ local_node.text = str(new_attr)
696
686
  serialized.append(local_node) # type: ignore
697
687
  else: # JSON
698
688
  for k in reversed(keys): # type: ignore
@@ -705,14 +695,15 @@ class Serializer(object):
705
695
  _serialized.update(_new_attr) # type: ignore
706
696
  _new_attr = _new_attr[k] # type: ignore
707
697
  _serialized = _serialized[k]
708
- except ValueError:
709
- continue
698
+ except ValueError as err:
699
+ if isinstance(err, SerializationError):
700
+ raise
710
701
 
711
702
  except (AttributeError, KeyError, TypeError) as err:
712
703
  msg = "Attribute {} in object {} cannot be serialized.\n{}".format(
713
704
  attr_name, class_name, str(target_obj)
714
705
  )
715
- raise_with_traceback(SerializationError, msg, err)
706
+ raise SerializationError(msg) from err
716
707
  else:
717
708
  return serialized
718
709
 
@@ -756,9 +747,9 @@ class Serializer(object):
756
747
  ]
757
748
  data = deserializer._deserialize(data_type, data)
758
749
  except DeserializationError as err:
759
- raise_with_traceback(
760
- SerializationError, "Unable to build a model: " + str(err), err
761
- )
750
+ raise SerializationError(
751
+ "Unable to build a model: " + str(err)
752
+ ) from err
762
753
 
763
754
  return self._serialize(data, data_type, **kwargs)
764
755
 
@@ -778,6 +769,7 @@ class Serializer(object):
778
769
 
779
770
  if kwargs.get("skip_quote") is True:
780
771
  output = str(output)
772
+ output = output.replace("{", quote("{")).replace("}", quote("}"))
781
773
  else:
782
774
  output = quote(str(output), safe="")
783
775
  except SerializationError:
@@ -790,7 +782,9 @@ class Serializer(object):
790
782
 
791
783
  :param data: The data to be serialized.
792
784
  :param str data_type: The type to be serialized from.
793
- :rtype: str
785
+ :keyword bool skip_quote: Whether to skip quote the serialized result.
786
+ Defaults to False.
787
+ :rtype: str, list
794
788
  :raises: TypeError if serialization fails.
795
789
  :raises: ValueError if data is None
796
790
  """
@@ -798,17 +792,10 @@ class Serializer(object):
798
792
  # Treat the list aside, since we don't want to encode the div separator
799
793
  if data_type.startswith("["):
800
794
  internal_data_type = data_type[1:-1]
801
- data = [
802
- (
803
- self.serialize_data(d, internal_data_type, **kwargs)
804
- if d is not None
805
- else ""
806
- )
807
- for d in data
808
- ]
809
- if not kwargs.get("skip_quote", False):
810
- data = [quote(str(d), safe="") for d in data]
811
- return str(self.serialize_iter(data, internal_data_type, **kwargs))
795
+ do_quote = not kwargs.get("skip_quote", False)
796
+ return self.serialize_iter(
797
+ data, internal_data_type, do_quote=do_quote, **kwargs
798
+ )
812
799
 
813
800
  # Not a list, regular serialization
814
801
  output = self.serialize_data(data, data_type, **kwargs)
@@ -859,7 +846,7 @@ class Serializer(object):
859
846
  raise ValueError("No value for given attribute")
860
847
 
861
848
  try:
862
- if data is AzureCoreNull:
849
+ if data is CoreNull:
863
850
  return None
864
851
  if data_type in self.basic_types.values():
865
852
  return self.serialize_basic(data, data_type, **kwargs)
@@ -879,7 +866,7 @@ class Serializer(object):
879
866
 
880
867
  except (ValueError, TypeError) as err:
881
868
  msg = "Unable to serialize value: {!r} as type: {!r}."
882
- raise_with_traceback(SerializationError, msg.format(data, data_type), err)
869
+ raise SerializationError(msg.format(data, data_type)) from err
883
870
  else:
884
871
  return self._serialize(data, **kwargs)
885
872
 
@@ -947,6 +934,8 @@ class Serializer(object):
947
934
  not be None or empty.
948
935
  :param str div: If set, this str will be used to combine the elements
949
936
  in the iterable into a combined string. Default is 'None'.
937
+ :keyword bool do_quote: Whether to quote the serialized result of each iterable element.
938
+ Defaults to False.
950
939
  :rtype: list, str
951
940
  """
952
941
  if isinstance(data, str):
@@ -959,9 +948,16 @@ class Serializer(object):
959
948
  for d in data:
960
949
  try:
961
950
  serialized.append(self.serialize_data(d, iter_type, **kwargs))
962
- except ValueError:
951
+ except ValueError as err:
952
+ if isinstance(err, SerializationError):
953
+ raise
963
954
  serialized.append(None)
964
955
 
956
+ if kwargs.get("do_quote", False):
957
+ serialized = [
958
+ "" if s is None else quote(str(s), safe="") for s in serialized
959
+ ]
960
+
965
961
  if div:
966
962
  serialized = ["" if s is None else str(s) for s in serialized]
967
963
  serialized = div.join(serialized)
@@ -1014,7 +1010,9 @@ class Serializer(object):
1014
1010
  serialized[self.serialize_unicode(key)] = self.serialize_data(
1015
1011
  value, dict_type, **kwargs
1016
1012
  )
1017
- except ValueError:
1013
+ except ValueError as err:
1014
+ if isinstance(err, SerializationError):
1015
+ raise
1018
1016
  serialized[self.serialize_unicode(key)] = None
1019
1017
 
1020
1018
  if "xml" in serialization_ctxt:
@@ -1049,7 +1047,7 @@ class Serializer(object):
1049
1047
  return self.serialize_basic(attr, self.basic_types[obj_type], **kwargs)
1050
1048
  if obj_type is _long_type:
1051
1049
  return self.serialize_long(attr)
1052
- if obj_type is unicode_str:
1050
+ if obj_type is str:
1053
1051
  return self.serialize_unicode(attr)
1054
1052
  if obj_type is datetime.datetime:
1055
1053
  return self.serialize_iso(attr)
@@ -1233,10 +1231,10 @@ class Serializer(object):
1233
1231
  return date + microseconds + "Z"
1234
1232
  except (ValueError, OverflowError) as err:
1235
1233
  msg = "Unable to serialize datetime object."
1236
- raise_with_traceback(SerializationError, msg, err)
1234
+ raise SerializationError(msg) from err
1237
1235
  except AttributeError as err:
1238
1236
  msg = "ISO-8601 object must be valid Datetime object."
1239
- raise_with_traceback(TypeError, msg, err)
1237
+ raise TypeError(msg) from err
1240
1238
 
1241
1239
  @staticmethod
1242
1240
  def serialize_unix(attr, **kwargs):
@@ -1272,7 +1270,6 @@ def rest_key_extractor(attr, attr_desc, data):
1272
1270
  if working_data is None:
1273
1271
  # If at any point while following flatten JSON path see None, it means
1274
1272
  # that all properties under are None as well
1275
- # https://github.com/Azure/msrest-for-python/issues/197
1276
1273
  return None
1277
1274
  key = ".".join(dict_keys[1:])
1278
1275
 
@@ -1295,7 +1292,6 @@ def rest_key_case_insensitive_extractor(attr, attr_desc, data):
1295
1292
  if working_data is None:
1296
1293
  # If at any point while following flatten JSON path see None, it means
1297
1294
  # that all properties under are None as well
1298
- # https://github.com/Azure/msrest-for-python/issues/197
1299
1295
  return None
1300
1296
  key = ".".join(dict_keys[1:])
1301
1297
 
@@ -1445,7 +1441,7 @@ class Deserializer(object):
1445
1441
  r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}" r"\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?"
1446
1442
  )
1447
1443
 
1448
- def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
1444
+ def __init__(self, classes: Optional[Mapping[str, type]] = None):
1449
1445
  self.deserialize_type = {
1450
1446
  "iso-8601": Deserializer.deserialize_iso,
1451
1447
  "rfc-1123": Deserializer.deserialize_rfc,
@@ -1465,7 +1461,7 @@ class Deserializer(object):
1465
1461
  "duration": (isodate.Duration, datetime.timedelta),
1466
1462
  "iso-8601": (datetime.datetime),
1467
1463
  }
1468
- self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {}
1464
+ self.dependencies: Dict[str, type] = dict(classes) if classes else {}
1469
1465
  self.key_extractors = [rest_key_extractor, xml_key_extractor]
1470
1466
  # Additional properties only works if the "rest_key_extractor" is used to
1471
1467
  # extract the keys. Making it to work whatever the key extractor is too much
@@ -1524,7 +1520,7 @@ class Deserializer(object):
1524
1520
 
1525
1521
  response, class_name = self._classify_target(target_obj, data)
1526
1522
 
1527
- if isinstance(response, basestring):
1523
+ if isinstance(response, str):
1528
1524
  return self.deserialize_data(data, response)
1529
1525
  elif isinstance(response, type) and issubclass(response, Enum):
1530
1526
  return self.deserialize_enum(data, response)
@@ -1561,7 +1557,7 @@ class Deserializer(object):
1561
1557
  d_attrs[attr] = value
1562
1558
  except (AttributeError, TypeError, KeyError) as err:
1563
1559
  msg = "Unable to deserialize to object: " + class_name # type: ignore
1564
- raise_with_traceback(DeserializationError, msg, err)
1560
+ raise DeserializationError(msg) from err
1565
1561
  else:
1566
1562
  additional_properties = self._build_additional_properties(attributes, data)
1567
1563
  return self._instantiate_model(response, d_attrs, additional_properties)
@@ -1598,14 +1594,14 @@ class Deserializer(object):
1598
1594
  if target is None:
1599
1595
  return None, None
1600
1596
 
1601
- if isinstance(target, basestring):
1597
+ if isinstance(target, str):
1602
1598
  try:
1603
1599
  target = self.dependencies[target]
1604
1600
  except KeyError:
1605
1601
  return target, target
1606
1602
 
1607
1603
  try:
1608
- target = target._classify(data, self.dependencies)
1604
+ target = target._classify(data, self.dependencies) # type: ignore
1609
1605
  except AttributeError:
1610
1606
  pass # Target is not a Model, no classify
1611
1607
  return target, target.__class__.__name__ # type: ignore
@@ -1668,7 +1664,7 @@ class Deserializer(object):
1668
1664
  raw_data.text, raw_data.headers
1669
1665
  )
1670
1666
 
1671
- if isinstance(raw_data, (basestring, bytes)) or hasattr(raw_data, "read"):
1667
+ if isinstance(raw_data, (str, bytes)) or hasattr(raw_data, "read"):
1672
1668
  return RawDeserializer.deserialize_from_text(raw_data, content_type) # type: ignore
1673
1669
  return raw_data
1674
1670
 
@@ -1756,7 +1752,7 @@ class Deserializer(object):
1756
1752
  except (ValueError, TypeError, AttributeError) as err:
1757
1753
  msg = "Unable to deserialize response data."
1758
1754
  msg += " Data: {}, {}".format(data, data_type)
1759
- raise_with_traceback(DeserializationError, msg, err)
1755
+ raise DeserializationError(msg) from err
1760
1756
  else:
1761
1757
  return self._deserialize(obj_type, data)
1762
1758
 
@@ -1812,7 +1808,7 @@ class Deserializer(object):
1812
1808
  if isinstance(attr, ET.Element):
1813
1809
  # Do no recurse on XML, just return the tree as-is
1814
1810
  return attr
1815
- if isinstance(attr, basestring):
1811
+ if isinstance(attr, str):
1816
1812
  return self.deserialize_basic(attr, "str")
1817
1813
  obj_type = type(attr)
1818
1814
  if obj_type in self.basic_types:
@@ -1869,7 +1865,7 @@ class Deserializer(object):
1869
1865
  if data_type == "bool":
1870
1866
  if attr in [True, False, 1, 0]:
1871
1867
  return bool(attr)
1872
- elif isinstance(attr, basestring):
1868
+ elif isinstance(attr, str):
1873
1869
  if attr.lower() in ["true", "1"]:
1874
1870
  return True
1875
1871
  elif attr.lower() in ["false", "0"]:
@@ -1920,7 +1916,6 @@ class Deserializer(object):
1920
1916
  data = data.value
1921
1917
  if isinstance(data, int):
1922
1918
  # Workaround. We might consider remove it in the future.
1923
- # https://github.com/Azure/azure-rest-api-specs/issues/141
1924
1919
  try:
1925
1920
  return list(enum_obj.__members__.values())[data]
1926
1921
  except IndexError:
@@ -1978,10 +1973,10 @@ class Deserializer(object):
1978
1973
  if isinstance(attr, ET.Element):
1979
1974
  attr = attr.text
1980
1975
  try:
1981
- return decimal.Decimal(attr) # type: ignore
1976
+ return decimal.Decimal(str(attr)) # type: ignore
1982
1977
  except decimal.DecimalException as err:
1983
1978
  msg = "Invalid decimal {}".format(attr)
1984
- raise_with_traceback(DeserializationError, msg, err)
1979
+ raise DeserializationError(msg) from err
1985
1980
 
1986
1981
  @staticmethod
1987
1982
  def deserialize_long(attr):
@@ -2009,7 +2004,7 @@ class Deserializer(object):
2009
2004
  duration = isodate.parse_duration(attr)
2010
2005
  except (ValueError, OverflowError, AttributeError) as err:
2011
2006
  msg = "Cannot deserialize duration object."
2012
- raise_with_traceback(DeserializationError, msg, err)
2007
+ raise DeserializationError(msg) from err
2013
2008
  else:
2014
2009
  return duration
2015
2010
 
@@ -2028,7 +2023,7 @@ class Deserializer(object):
2028
2023
  "Date must have only digits and -. Received: %s" % attr
2029
2024
  )
2030
2025
  # This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
2031
- return isodate.parse_date(attr, defaultmonth=None, defaultday=None)
2026
+ return isodate.parse_date(attr, defaultmonth=0, defaultday=0)
2032
2027
 
2033
2028
  @staticmethod
2034
2029
  def deserialize_time(attr):
@@ -2068,7 +2063,7 @@ class Deserializer(object):
2068
2063
  date_obj = date_obj.astimezone(tz=TZ_UTC)
2069
2064
  except ValueError as err:
2070
2065
  msg = "Cannot deserialize to rfc datetime object."
2071
- raise_with_traceback(DeserializationError, msg, err)
2066
+ raise DeserializationError(msg) from err
2072
2067
  else:
2073
2068
  return date_obj
2074
2069
 
@@ -2105,7 +2100,7 @@ class Deserializer(object):
2105
2100
  raise OverflowError("Hit max or min date")
2106
2101
  except (ValueError, OverflowError, AttributeError) as err:
2107
2102
  msg = "Cannot deserialize datetime object."
2108
- raise_with_traceback(DeserializationError, msg, err)
2103
+ raise DeserializationError(msg) from err
2109
2104
  else:
2110
2105
  return date_obj
2111
2106
 
@@ -2121,9 +2116,10 @@ class Deserializer(object):
2121
2116
  if isinstance(attr, ET.Element):
2122
2117
  attr = int(attr.text) # type: ignore
2123
2118
  try:
2119
+ attr = int(attr)
2124
2120
  date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC)
2125
2121
  except ValueError as err:
2126
2122
  msg = "Cannot deserialize to unix datetime object."
2127
- raise_with_traceback(DeserializationError, msg, err)
2123
+ raise DeserializationError(msg) from err
2128
2124
  else:
2129
2125
  return date_obj
diracx/client/_vendor.py CHANGED
@@ -1,23 +1,11 @@
1
1
  # --------------------------------------------------------------------------
2
- # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.1, generator: @autorest/python@6.4.11)
2
+ # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.9)
3
3
  # Changes may cause incorrect behavior and will be lost if the code is regenerated.
4
4
  # --------------------------------------------------------------------------
5
5
 
6
- from typing import List, cast
6
+ from typing import Optional
7
7
 
8
-
9
- def _format_url_section(template, **kwargs):
10
- components = template.split("/")
11
- while components:
12
- try:
13
- return template.format(**kwargs)
14
- except KeyError as key:
15
- # Need the cast, as for some reasons "split" is typed as list[str | Any]
16
- formatted_components = cast(List[str], template.split("/"))
17
- components = [
18
- c for c in formatted_components if "{}".format(key.args[0]) not in c
19
- ]
20
- template = "/".join(components)
8
+ from azure.core import MatchConditions
21
9
 
22
10
 
23
11
  def raise_if_not_implemented(cls, abstract_methods):
@@ -31,3 +19,37 @@ def raise_if_not_implemented(cls, abstract_methods):
31
19
  cls.__name__, "', '".join(not_implemented)
32
20
  )
33
21
  )
22
+
23
+
24
+ def quote_etag(etag: Optional[str]) -> Optional[str]:
25
+ if not etag or etag == "*":
26
+ return etag
27
+ if etag.startswith("W/"):
28
+ return etag
29
+ if etag.startswith('"') and etag.endswith('"'):
30
+ return etag
31
+ if etag.startswith("'") and etag.endswith("'"):
32
+ return etag
33
+ return '"' + etag + '"'
34
+
35
+
36
+ def prep_if_match(
37
+ etag: Optional[str], match_condition: Optional[MatchConditions]
38
+ ) -> Optional[str]:
39
+ if match_condition == MatchConditions.IfNotModified:
40
+ if_match = quote_etag(etag) if etag else None
41
+ return if_match
42
+ if match_condition == MatchConditions.IfPresent:
43
+ return "*"
44
+ return None
45
+
46
+
47
+ def prep_if_none_match(
48
+ etag: Optional[str], match_condition: Optional[MatchConditions]
49
+ ) -> Optional[str]:
50
+ if match_condition == MatchConditions.IfModified:
51
+ if_none_match = quote_etag(etag) if etag else None
52
+ return if_none_match
53
+ if match_condition == MatchConditions.IfMissing:
54
+ return "*"
55
+ return None
@@ -1,6 +1,6 @@
1
1
  # coding=utf-8
2
2
  # --------------------------------------------------------------------------
3
- # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.1, generator: @autorest/python@6.4.11)
3
+ # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.9)
4
4
  # Changes may cause incorrect behavior and will be lost if the code is regenerated.
5
5
  # --------------------------------------------------------------------------
6
6