Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Release History

## 1.1.1 (Unreleased)
## 1.2.0b1 (2023-08-04)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
- Number Lookup API public preview
- API version `2023-05-01-preview` is the default

## 1.1.0 (2023-03-28)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
PhoneNumberCountry,
PhoneNumberLocality,
PhoneNumberOffering,
OperatorInformationResult,
)

__all__ = [
Expand All @@ -36,5 +37,6 @@
'PhoneNumberCountry',
'PhoneNumberLocality',
'PhoneNumberOffering',
'OperatorInformationResult',
'PhoneNumbersClient'
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class ApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
V2022_01_11_PREVIEW2 = "2022-01-11-preview2"
V2022_12_01 = "2022-12-01"
V2023_05_01_PREVIEW = "2023-05-01-preview"


DEFAULT_VERSION = ApiVersion.V2022_12_01
DEFAULT_VERSION = ApiVersion.V2023_05_01_PREVIEW
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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 "2022-12-01". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: Api Version. Default value is "2023-05-01-preview". 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 +39,7 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
) -> None:
_endpoint = "{endpoint}"
self._config = PhoneNumbersClientConfiguration(endpoint=endpoint, **kwargs)
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **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 Down Expand Up @@ -81,5 +81,5 @@ def __enter__(self) -> "PhoneNumbersClient":
self._client.__enter__()
return self

def __exit__(self, *exc_details) -> None:
def __exit__(self, *exc_details: Any) -> None:
self._client.__exit__(*exc_details)
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

import sys
from typing import Any

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

if sys.version_info >= (3, 8):
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
else:
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports

VERSION = "unknown"


Expand All @@ -29,14 +23,14 @@ 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 "2022-12-01". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: Api Version. Default value is "2023-05-01-preview". 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: Literal["2022-12-01"] = kwargs.pop("api_version", "2022-12-01")
api_version: str = kwargs.pop("api_version", "2023-05-01-preview")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@
import re
import sys
import codecs
from typing import Dict, Any, cast, Optional, Union, AnyStr, IO, Mapping, Callable, TypeVar, MutableMapping, Type
from typing import (
Dict,
Any,
cast,
Optional,
Union,
AnyStr,
IO,
Mapping,
Callable,
TypeVar,
MutableMapping,
Type,
List,
Mapping,
)

try:
from urllib import quote # type: ignore
Expand All @@ -49,6 +64,7 @@
import isodate # type: ignore

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

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

Expand Down Expand Up @@ -343,7 +359,7 @@ def as_dict(
key_transformer: Callable[[str, Dict[str, Any], Any], Any] = attribute_transformer,
**kwargs: Any
) -> JSON:
"""Return a dict that can be JSONify using json.dump.
"""Return a dict that can be serialized using json.dump.

Advanced usage might optionally use a callback as parameter:

Expand Down Expand Up @@ -421,7 +437,7 @@ def from_dict(
"""
deserializer = Deserializer(cls._infer_class_models())
deserializer.key_extractors = ( # type: ignore
[
[ # type: ignore
attribute_key_case_insensitive_extractor,
rest_key_case_insensitive_extractor,
last_rest_key_case_insensitive_extractor,
Expand Down Expand Up @@ -529,7 +545,7 @@ class Serializer(object):
"multiple": lambda x, y: x % y != 0,
}

def __init__(self, classes=None):
def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
self.serialize_type = {
"iso-8601": Serializer.serialize_iso,
"rfc-1123": Serializer.serialize_rfc,
Expand All @@ -545,7 +561,7 @@ def __init__(self, classes=None):
"[]": self.serialize_iter,
"{}": self.serialize_dict,
}
self.dependencies = dict(classes) if classes else {}
self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {}
self.key_transformer = full_restapi_key_transformer
self.client_side_validation = True

Expand Down Expand Up @@ -613,7 +629,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
if xml_desc.get("attr", False):
if xml_ns:
ET.register_namespace(xml_prefix, xml_ns)
xml_name = "{}{}".format(xml_ns, xml_name)
xml_name = "{{{}}}{}".format(xml_ns, xml_name)
serialized.set(xml_name, new_attr) # type: ignore
continue
if xml_desc.get("text", False):
Expand All @@ -637,8 +653,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
serialized.append(local_node) # type: ignore
else: # JSON
for k in reversed(keys): # type: ignore
unflattened = {k: new_attr}
new_attr = unflattened
new_attr = {k: new_attr}

_new_attr = new_attr
_serialized = serialized
Expand All @@ -647,8 +662,9 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
_serialized.update(_new_attr) # type: ignore
_new_attr = _new_attr[k] # type: ignore
_serialized = _serialized[k]
except ValueError:
continue
except ValueError as err:
if isinstance(err, SerializationError):
raise

except (AttributeError, KeyError, TypeError) as err:
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
Expand All @@ -667,8 +683,8 @@ def body(self, data, data_type, **kwargs):
"""

# Just in case this is a dict
internal_data_type = data_type.strip("[]{}")
internal_data_type = self.dependencies.get(internal_data_type, None)
internal_data_type_str = data_type.strip("[]{}")
internal_data_type = self.dependencies.get(internal_data_type_str, None)
try:
is_xml_model_serialization = kwargs["is_xml"]
except KeyError:
Expand Down Expand Up @@ -726,6 +742,8 @@ def query(self, name, data, data_type, **kwargs):

:param data: The data to be serialized.
:param str data_type: The type to be serialized from.
:keyword bool skip_quote: Whether to skip quote the serialized result.
Defaults to False.
:rtype: str
:raises: TypeError if serialization fails.
:raises: ValueError if data is None
Expand All @@ -734,10 +752,8 @@ def query(self, name, data, data_type, **kwargs):
# Treat the list aside, since we don't want to encode the div separator
if data_type.startswith("["):
internal_data_type = data_type[1:-1]
data = [self.serialize_data(d, internal_data_type, **kwargs) if d is not None else "" for d in data]
if not kwargs.get("skip_quote", False):
data = [quote(str(d), safe="") for d in data]
return str(self.serialize_iter(data, internal_data_type, **kwargs))
do_quote = not kwargs.get("skip_quote", False)
return str(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 @@ -788,6 +804,8 @@ def serialize_data(self, data, data_type, **kwargs):
raise ValueError("No value for given attribute")

try:
if data is AzureCoreNull:
return None
if data_type in self.basic_types.values():
return self.serialize_basic(data, data_type, **kwargs)

Expand Down Expand Up @@ -874,6 +892,8 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
not be None or empty.
:param str div: If set, this str will be used to combine the elements
in the iterable into a combined string. Default is 'None'.
:keyword bool do_quote: Whether to quote the serialized result of each iterable element.
Defaults to False.
:rtype: list, str
"""
if isinstance(data, str):
Expand All @@ -886,9 +906,14 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
for d in data:
try:
serialized.append(self.serialize_data(d, iter_type, **kwargs))
except ValueError:
except ValueError as err:
if isinstance(err, SerializationError):
raise
serialized.append(None)

if kwargs.get("do_quote", False):
serialized = ["" if s is None else quote(str(s), safe="") for s in serialized]

if div:
serialized = ["" if s is None else str(s) for s in serialized]
serialized = div.join(serialized)
Expand Down Expand Up @@ -933,7 +958,9 @@ def serialize_dict(self, attr, dict_type, **kwargs):
for key, value in attr.items():
try:
serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs)
except ValueError:
except ValueError as err:
if isinstance(err, SerializationError):
raise
serialized[self.serialize_unicode(key)] = None

if "xml" in serialization_ctxt:
Expand Down Expand Up @@ -1172,7 +1199,8 @@ def rest_key_extractor(attr, attr_desc, data):
working_data = data

while "." in key:
dict_keys = _FLATTEN.split(key)
# Need the cast, as for some reasons "split" is typed as list[str | Any]
dict_keys = cast(List[str], _FLATTEN.split(key))
if len(dict_keys) == 1:
key = _decode_attribute_map_key(dict_keys[0])
break
Expand Down Expand Up @@ -1253,7 +1281,7 @@ def _extract_name_from_internal_type(internal_type):
xml_name = internal_type_xml_map.get("name", internal_type.__name__)
xml_ns = internal_type_xml_map.get("ns", None)
if xml_ns:
xml_name = "{}{}".format(xml_ns, xml_name)
xml_name = "{{{}}}{}".format(xml_ns, xml_name)
return xml_name


Expand All @@ -1277,7 +1305,7 @@ def xml_key_extractor(attr, attr_desc, data):
# Integrate namespace if necessary
xml_ns = xml_desc.get("ns", internal_type_xml_map.get("ns", None))
if xml_ns:
xml_name = "{}{}".format(xml_ns, xml_name)
xml_name = "{{{}}}{}".format(xml_ns, xml_name)

# If it's an attribute, that's simple
if xml_desc.get("attr", False):
Expand Down Expand Up @@ -1343,7 +1371,7 @@ class Deserializer(object):

valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}" r"\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?")

def __init__(self, classes=None):
def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
self.deserialize_type = {
"iso-8601": Deserializer.deserialize_iso,
"rfc-1123": Deserializer.deserialize_rfc,
Expand All @@ -1363,7 +1391,7 @@ def __init__(self, classes=None):
"duration": (isodate.Duration, datetime.timedelta),
"iso-8601": (datetime.datetime),
}
self.dependencies = dict(classes) if classes else {}
self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {}
self.key_extractors = [rest_key_extractor, xml_key_extractor]
# Additional properties only works if the "rest_key_extractor" is used to
# extract the keys. Making it to work whatever the key extractor is too much
Expand Down Expand Up @@ -1482,7 +1510,7 @@ def _classify_target(self, target, data):
Once classification has been determined, initialize object.

:param str target: The target object type to deserialize to.
:param str/dict data: The response data to deseralize.
:param str/dict data: The response data to deserialize.
"""
if target is None:
return None, None
Expand All @@ -1497,7 +1525,7 @@ def _classify_target(self, target, data):
target = target._classify(data, self.dependencies)
except AttributeError:
pass # Target is not a Model, no classify
return target, target.__class__.__name__
return target, target.__class__.__name__ # type: ignore

def failsafe_deserialize(self, target_obj, data, content_type=None):
"""Ignores any errors encountered in deserialization,
Expand All @@ -1507,7 +1535,7 @@ def failsafe_deserialize(self, target_obj, data, content_type=None):
a deserialization error.

:param str target_obj: The target object type to deserialize to.
:param str/dict data: The response data to deseralize.
:param str/dict data: The response data to deserialize.
:param str content_type: Swagger "produces" if available.
"""
try:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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 "2022-12-01". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: Api Version. Default value is "2023-05-01-preview". 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 +39,7 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
) -> None:
_endpoint = "{endpoint}"
self._config = PhoneNumbersClientConfiguration(endpoint=endpoint, **kwargs)
self._client = AsyncPipelineClient(base_url=_endpoint, config=self._config, **kwargs)
self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=_endpoint, config=self._config, **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 Down Expand Up @@ -81,5 +81,5 @@ async def __aenter__(self) -> "PhoneNumbersClient":
await self._client.__aenter__()
return self

async def __aexit__(self, *exc_details) -> None:
async def __aexit__(self, *exc_details: Any) -> None:
await self._client.__aexit__(*exc_details)
Loading