Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update generated files
  • Loading branch information
ericasp16 committed Nov 17, 2023
commit c6141342d847d12ef761583ab11a0b2fd200576f
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any

from azure.core import PipelineClient
from azure.core.pipeline import policies
from azure.core.rest import HttpRequest, HttpResponse

from . import models as _models
Expand All @@ -27,8 +28,8 @@ class PhoneNumbersClient: # pylint: disable=client-accepts-api-version-keyword
:param endpoint: The communication resource, for example
https://resourcename.communication.azure.com. Required.
:type endpoint: str
:keyword api_version: Api Version. Default value is "2023-05-01-preview". Note that overriding
this default value may result in unsupported behavior.
:keyword api_version: Api Version. Default value is "2024-03-01". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
Expand All @@ -39,7 +40,24 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
) -> None:
_endpoint = "{endpoint}"
self._config = PhoneNumbersClientConfiguration(endpoint=endpoint, **kwargs)
self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
_policies = kwargs.pop("policies", None)
if _policies is None:
_policies = [
policies.RequestIdPolicy(**kwargs),
self._config.headers_policy,
self._config.user_agent_policy,
self._config.proxy_policy,
policies.ContentDecodePolicy(**kwargs),
self._config.redirect_policy,
self._config.retry_policy,
self._config.authentication_policy,
self._config.custom_hook_policy,
self._config.logging_policy,
policies.DistributedTracingPolicy(**kwargs),
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
self._config.http_logging_policy,
]
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)

client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)}
client_models.update({k: v for k, v in _models.__dict__.items() if isinstance(v, type)})
Expand All @@ -48,7 +66,7 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self._serialize.client_side_validation = False
self.phone_numbers = PhoneNumbersOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.

>>> from azure.core.rest import HttpRequest
Expand All @@ -72,7 +90,7 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
return self._client.send_request(request_copy, **kwargs)
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

def close(self) -> None:
self._client.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

from typing import Any

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

VERSION = "unknown"


class PhoneNumbersClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
class PhoneNumbersClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
"""Configuration for PhoneNumbersClient.

Note that all parameters used to create this instance are saved as instance
Expand All @@ -23,21 +22,21 @@ class PhoneNumbersClientConfiguration(Configuration): # pylint: disable=too-man
:param endpoint: The communication resource, for example
https://resourcename.communication.azure.com. Required.
:type endpoint: str
:keyword api_version: Api Version. Default value is "2023-05-01-preview". Note that overriding
this default value may result in unsupported behavior.
:keyword api_version: Api Version. Default value is "2024-03-01". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, endpoint: str, **kwargs: Any) -> None:
super(PhoneNumbersClientConfiguration, self).__init__(**kwargs)
api_version: str = kwargs.pop("api_version", "2023-05-01-preview")
api_version: str = kwargs.pop("api_version", "2024-03-01")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")

self.endpoint = endpoint
self.api_version = api_version
kwargs.setdefault("sdk_moniker", "phonenumbersclient/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

def _configure(self, **kwargs: Any) -> None:
Expand All @@ -46,7 +45,7 @@ def _configure(self, **kwargs: Any) -> None:
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@

import isodate # type: ignore

from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback
from azure.core.serialization import NULL as AzureCoreNull
from azure.core.exceptions import DeserializationError, SerializationError
from azure.core.serialization import NULL as CoreNull

_BOM = codecs.BOM_UTF8.decode(encoding="utf-8")

Expand Down Expand Up @@ -124,7 +124,7 @@ def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type:
pass

return ET.fromstring(data_as_str) # nosec
except ET.ParseError:
except ET.ParseError as err:
# It might be because the server has an issue, and returned JSON with
# content-type XML....
# So let's try a JSON load, and if it's still broken
Expand All @@ -143,7 +143,7 @@ def _json_attemp(data):
# The function hack is because Py2.7 messes up with exception
# context otherwise.
_LOGGER.critical("Wasn't XML not JSON, failing")
raise_with_traceback(DeserializationError, "XML is invalid")
raise DeserializationError("XML is invalid") from err
raise DeserializationError("Cannot deserialize content-type: {}".format(content_type))

@classmethod
Expand Down Expand Up @@ -295,7 +295,7 @@ class Model(object):
_validation: Dict[str, Dict[str, Any]] = {}

def __init__(self, **kwargs: Any) -> None:
self.additional_properties: Dict[str, Any] = {}
self.additional_properties: Optional[Dict[str, Any]] = {}
for k in kwargs:
if k not in self._attribute_map:
_LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__)
Expand Down Expand Up @@ -340,7 +340,7 @@ def _create_xml_node(cls):
return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None))

def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
"""Return the JSON that would be sent to azure from this model.
"""Return the JSON that would be sent to server from this model.

This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`.

Expand All @@ -351,7 +351,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
:rtype: dict
"""
serializer = Serializer(self._infer_class_models())
return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs)
return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore

def as_dict(
self,
Expand Down Expand Up @@ -390,7 +390,7 @@ def my_key_transformer(key, attr_desc, value):
:rtype: dict
"""
serializer = Serializer(self._infer_class_models())
return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs)
return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore

@classmethod
def _infer_class_models(cls):
Expand All @@ -415,7 +415,7 @@ def deserialize(cls: Type[ModelType], data: Any, content_type: Optional[str] = N
:raises: DeserializationError if something went wrong
"""
deserializer = Deserializer(cls._infer_class_models())
return deserializer(cls.__name__, data, content_type=content_type)
return deserializer(cls.__name__, data, content_type=content_type) # type: ignore

@classmethod
def from_dict(
Expand Down Expand Up @@ -445,7 +445,7 @@ def from_dict(
if key_extractors is None
else key_extractors
)
return deserializer(cls.__name__, data, content_type=content_type)
return deserializer(cls.__name__, data, content_type=content_type) # type: ignore

@classmethod
def _flatten_subtype(cls, key, objects):
Expand Down Expand Up @@ -668,7 +668,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):

except (AttributeError, KeyError, TypeError) as err:
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
raise_with_traceback(SerializationError, msg, err)
raise SerializationError(msg) from err
else:
return serialized

Expand Down Expand Up @@ -710,7 +710,7 @@ def body(self, data, data_type, **kwargs):
]
data = deserializer._deserialize(data_type, data)
except DeserializationError as err:
raise_with_traceback(SerializationError, "Unable to build a model: " + str(err), err)
raise SerializationError("Unable to build a model: " + str(err)) from err

return self._serialize(data, data_type, **kwargs)

Expand All @@ -730,6 +730,7 @@ def url(self, name, data, data_type, **kwargs):

if kwargs.get("skip_quote") is True:
output = str(output)
output = output.replace("{", quote("{")).replace("}", quote("}"))
else:
output = quote(str(output), safe="")
except SerializationError:
Expand All @@ -753,7 +754,7 @@ def query(self, name, data, data_type, **kwargs):
if data_type.startswith("["):
internal_data_type = data_type[1:-1]
do_quote = not kwargs.get("skip_quote", False)
return str(self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs))
return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs)

# Not a list, regular serialization
output = self.serialize_data(data, data_type, **kwargs)
Expand Down Expand Up @@ -804,7 +805,7 @@ def serialize_data(self, data, data_type, **kwargs):
raise ValueError("No value for given attribute")

try:
if data is AzureCoreNull:
if data is CoreNull:
return None
if data_type in self.basic_types.values():
return self.serialize_basic(data, data_type, **kwargs)
Expand All @@ -824,7 +825,7 @@ def serialize_data(self, data, data_type, **kwargs):

except (ValueError, TypeError) as err:
msg = "Unable to serialize value: {!r} as type: {!r}."
raise_with_traceback(SerializationError, msg.format(data, data_type), err)
raise SerializationError(msg.format(data, data_type)) from err
else:
return self._serialize(data, **kwargs)

Expand Down Expand Up @@ -1170,10 +1171,10 @@ def serialize_iso(attr, **kwargs):
return date + microseconds + "Z"
except (ValueError, OverflowError) as err:
msg = "Unable to serialize datetime object."
raise_with_traceback(SerializationError, msg, err)
raise SerializationError(msg) from err
except AttributeError as err:
msg = "ISO-8601 object must be valid Datetime object."
raise_with_traceback(TypeError, msg, err)
raise TypeError(msg) from err

@staticmethod
def serialize_unix(attr, **kwargs):
Expand Down Expand Up @@ -1209,7 +1210,6 @@ def rest_key_extractor(attr, attr_desc, data):
if working_data is None:
# If at any point while following flatten JSON path see None, it means
# that all properties under are None as well
# https://github.com/Azure/msrest-for-python/issues/197
return None
key = ".".join(dict_keys[1:])

Expand All @@ -1230,7 +1230,6 @@ def rest_key_case_insensitive_extractor(attr, attr_desc, data):
if working_data is None:
# If at any point while following flatten JSON path see None, it means
# that all properties under are None as well
# https://github.com/Azure/msrest-for-python/issues/197
return None
key = ".".join(dict_keys[1:])

Expand Down Expand Up @@ -1481,7 +1480,7 @@ def _deserialize(self, target_obj, data):
d_attrs[attr] = value
except (AttributeError, TypeError, KeyError) as err:
msg = "Unable to deserialize to object: " + class_name # type: ignore
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
additional_properties = self._build_additional_properties(attributes, data)
return self._instantiate_model(response, d_attrs, additional_properties)
Expand Down Expand Up @@ -1652,7 +1651,7 @@ def deserialize_data(self, data, data_type):
except (ValueError, TypeError, AttributeError) as err:
msg = "Unable to deserialize response data."
msg += " Data: {}, {}".format(data, data_type)
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return self._deserialize(obj_type, data)

Expand Down Expand Up @@ -1808,7 +1807,6 @@ def deserialize_enum(data, enum_obj):
data = data.value
if isinstance(data, int):
# Workaround. We might consider remove it in the future.
# https://github.com/Azure/azure-rest-api-specs/issues/141
try:
return list(enum_obj.__members__.values())[data]
except IndexError:
Expand Down Expand Up @@ -1865,7 +1863,7 @@ def deserialize_decimal(attr):
return decimal.Decimal(attr) # type: ignore
except decimal.DecimalException as err:
msg = "Invalid decimal {}".format(attr)
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err

@staticmethod
def deserialize_long(attr):
Expand Down Expand Up @@ -1893,7 +1891,7 @@ def deserialize_duration(attr):
duration = isodate.parse_duration(attr)
except (ValueError, OverflowError, AttributeError) as err:
msg = "Cannot deserialize duration object."
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return duration

Expand All @@ -1910,7 +1908,7 @@ def deserialize_date(attr):
if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore
raise DeserializationError("Date must have only digits and -. Received: %s" % attr)
# This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
return isodate.parse_date(attr, defaultmonth=None, defaultday=None)
return isodate.parse_date(attr, defaultmonth=0, defaultday=0)

@staticmethod
def deserialize_time(attr):
Expand Down Expand Up @@ -1945,7 +1943,7 @@ def deserialize_rfc(attr):
date_obj = date_obj.astimezone(tz=TZ_UTC)
except ValueError as err:
msg = "Cannot deserialize to rfc datetime object."
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return date_obj

Expand Down Expand Up @@ -1982,7 +1980,7 @@ def deserialize_iso(attr):
raise OverflowError("Hit max or min date")
except (ValueError, OverflowError, AttributeError) as err:
msg = "Cannot deserialize datetime object."
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return date_obj

Expand All @@ -2001,6 +1999,6 @@ def deserialize_unix(attr):
date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC)
except ValueError as err:
msg = "Cannot deserialize to unix datetime object."
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return date_obj
Loading