Skip to content
Closed
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
6 changes: 6 additions & 0 deletions sdk/communication/azure-communication-messages/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"commit": "26af8eff710ea634da1b33fed369967d1c39b689",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"typespec_src": "specification/communication/Communication.Messages",
"@azure-tools/typespec-python": "0.36.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
# pylint: disable=wrong-import-position

from ._client import NotificationMessagesClient
from ._client import MessageTemplateClient
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ._patch import * # pylint: disable=unused-wildcard-import

from ._client import NotificationMessagesClient # type: ignore
from ._client import MessageTemplateClient # type: ignore
from ._version import VERSION

__version__ = VERSION

try:
from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
from ._patch import *
except ImportError:
_patch_all = []
from ._patch import patch_sdk as _patch_sdk
Expand All @@ -23,6 +29,6 @@
"NotificationMessagesClient",
"MessageTemplateClient",
]
__all__.extend([p for p in _patch_all if p not in __all__])
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore

_patch_sdk()

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
from ._serialization import Deserializer, Serializer

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential


class NotificationMessagesClient(
NotificationMessagesClientOperationsMixin
): # pylint: disable=client-accepts-api-version-keyword
class NotificationMessagesClient(NotificationMessagesClientOperationsMixin):
"""NotificationMessagesClient.

:param endpoint: The communication resource, for example
Expand Down Expand Up @@ -104,7 +101,7 @@ def __exit__(self, *exc_details: Any) -> None:
self._client.__exit__(*exc_details)


class MessageTemplateClient(MessageTemplateClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
class MessageTemplateClient(MessageTemplateClientOperationsMixin):
"""MessageTemplateClient.

:param endpoint: The communication resource, for example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
from ._version import VERSION

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential


class NotificationMessagesClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
class NotificationMessagesClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for NotificationMessagesClient.

Note that all parameters used to create this instance are saved as instance
Expand Down Expand Up @@ -73,7 +72,7 @@ def _configure(self, **kwargs: Any) -> None:
self.authentication_policy = self._infer_policy(**kwargs)


class MessageTemplateClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
class MessageTemplateClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for MessageTemplateClient.

Note that all parameters used to create this instance are saved as instance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# pylint: disable=too-many-lines
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# pylint: disable=protected-access, arguments-differ, signature-differs, broad-except, too-many-lines
# pylint: disable=protected-access, broad-except

import copy
import calendar
Expand Down Expand Up @@ -573,7 +574,7 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
def copy(self) -> "Model":
return Model(self.__dict__)

def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self: # pylint: disable=unused-argument
def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self:
if f"{cls.__module__}.{cls.__qualname__}" not in cls._calculated:
# we know the last nine classes in mro are going to be 'Model', '_MyMutableMapping', 'MutableMapping',
# 'Mapping', 'Collection', 'Sized', 'Iterable', 'Container' and 'object'
Expand All @@ -584,8 +585,8 @@ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self: # pylint: di
annotations = {
k: v
for mro_class in mros
if hasattr(mro_class, "__annotations__") # pylint: disable=no-member
for k, v in mro_class.__annotations__.items() # pylint: disable=no-member
if hasattr(mro_class, "__annotations__")
for k, v in mro_class.__annotations__.items()
}
for attr, rf in attr_to_rest_field.items():
rf._module = cls.__module__
Expand All @@ -600,8 +601,8 @@ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self: # pylint: di

def __init_subclass__(cls, discriminator: typing.Optional[str] = None) -> None:
for base in cls.__bases__:
if hasattr(base, "__mapping__"): # pylint: disable=no-member
base.__mapping__[discriminator or cls.__name__] = cls # type: ignore # pylint: disable=no-member
if hasattr(base, "__mapping__"):
base.__mapping__[discriminator or cls.__name__] = cls # type: ignore

@classmethod
def _get_discriminator(cls, exist_discriminators) -> typing.Optional["_RestField"]:
Expand All @@ -612,7 +613,7 @@ def _get_discriminator(cls, exist_discriminators) -> typing.Optional["_RestField

@classmethod
def _deserialize(cls, data, exist_discriminators):
if not hasattr(cls, "__mapping__"): # pylint: disable=no-member
if not hasattr(cls, "__mapping__"):
return cls(data)
discriminator = cls._get_discriminator(exist_discriminators)
if discriminator is None:
Expand All @@ -632,11 +633,11 @@ def _deserialize(cls, data, exist_discriminators):
discriminator_value = data.find(xml_name).text # pyright: ignore
else:
discriminator_value = data.get(discriminator._rest_name)
mapped_cls = cls.__mapping__.get(discriminator_value, cls) # pyright: ignore # pylint: disable=no-member
mapped_cls = cls.__mapping__.get(discriminator_value, cls) # pyright: ignore
return mapped_cls._deserialize(data, exist_discriminators)

def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing.Any]:
"""Return a dict that can be JSONify using json.dump.
"""Return a dict that can be turned into json using json.dump.

:keyword bool exclude_readonly: Whether to remove the readonly properties.
:returns: A dict JSON compatible object
Expand Down Expand Up @@ -733,7 +734,7 @@ def _sorted_annotations(types: typing.List[typing.Any]) -> typing.List[typing.An
)


def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915, R0912
def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-return-statements, too-many-branches
annotation: typing.Any,
module: typing.Optional[str],
rf: typing.Optional["_RestField"] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
# pylint: disable=wrong-import-position

from ._operations import NotificationMessagesClientOperationsMixin
from ._operations import MessageTemplateClientOperationsMixin
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ._patch import * # pylint: disable=unused-wildcard-import

from ._operations import NotificationMessagesClientOperationsMixin # type: ignore
from ._operations import MessageTemplateClientOperationsMixin # type: ignore

from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
from ._patch import *
from ._patch import patch_sdk as _patch_sdk

__all__ = [
"NotificationMessagesClientOperationsMixin",
"MessageTemplateClientOperationsMixin",
]
__all__.extend([p for p in _patch_all if p not in __all__])
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
_patch_sdk()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=too-many-lines,too-many-statements
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
Expand All @@ -10,7 +9,7 @@
from io import IOBase
import json
import sys
from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Optional, Type, TypeVar, Union, overload
from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Optional, TypeVar, Union, overload
import urllib.parse
import uuid

Expand Down Expand Up @@ -38,7 +37,7 @@
if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
else:
from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports
from typing import MutableMapping # type: ignore
JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object
T = TypeVar("T")
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
Expand Down Expand Up @@ -190,7 +189,7 @@ def send(
:rtype: ~azure.communication.messages.models.SendMessageResult
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = { # pylint: disable=unsubscriptable-object
error_map: MutableMapping = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down Expand Up @@ -267,7 +266,7 @@ def download_media(self, id: str, **kwargs: Any) -> Iterator[bytes]:
:rtype: Iterator[bytes]
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = { # pylint: disable=unsubscriptable-object
error_map: MutableMapping = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down Expand Up @@ -339,7 +338,7 @@ def list_templates(self, channel_id: str, **kwargs: Any) -> Iterable["_models.Me
maxpagesize = kwargs.pop("maxpagesize", None)
cls: ClsType[List[_models.MessageTemplateItem]] = kwargs.pop("cls", None)

error_map: MutableMapping[int, Type[HttpResponseError]] = { # pylint: disable=unsubscriptable-object
error_map: MutableMapping = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,132 +6,9 @@

Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
from typing import List, Any, Union
from urllib.parse import urlparse
from azure.core.credentials import TokenCredential, AzureKeyCredential
from ._shared.utils import parse_connection_str
from ._client import (
NotificationMessagesClient as NotificationMessagesClientGenerated,
MessageTemplateClient as MessageTemplateClientGenerated,
)
from ._shared.auth_policy_utils import get_authentication_policy
from ._api_versions import DEFAULT_VERSION
from typing import List


class NotificationMessagesClient(NotificationMessagesClientGenerated):
"""A client to interact with the AzureCommunicationService Messaging service.

This client provides operations to create and update jobs, policies and workers.

:param str endpoint:
The endpoint of the Azure Communication resource.
:param Union[TokenCredential, AsyncTokenCredential] credential:
The credentials with which to authenticate

:keyword api_version: Azure Communication Messaging API version.
Default value is "2023-11-01".
Note that overriding this default value may result in unsupported behavior.
"""

def __init__(self, endpoint: str, credential: Union[TokenCredential, AzureKeyCredential], **kwargs: Any) -> None:
if not credential:
raise ValueError("credential can not be None")

try:
if not endpoint.lower().startswith("http"):
endpoint = "https://" + endpoint
except AttributeError:
raise ValueError("Host URL must be a string") # pylint:disable=raise-missing-from

parsed_url = urlparse(endpoint.rstrip("/"))
if not parsed_url.netloc:
raise ValueError("Invalid URL: {}".format(endpoint))

self._endpoint = endpoint
self._api_version = kwargs.pop("api_version", DEFAULT_VERSION)
self._authentication_policy = get_authentication_policy(endpoint, credential)
self._credential = credential
super().__init__(
self._endpoint,
self._credential,
authentication_policy=self._authentication_policy,
api_version=self._api_version,
**kwargs
)

@classmethod
def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "NotificationMessagesClient":
"""Create NotificationMessagesClient from a Connection String.

:param conn_str: Azure communication service connection string. Required.
:type conn_str: str
:return: instance of NotificationMessagesClient
:rtype:
~azure.communication.messages.NotificationMessagesClient
"""
endpoint, access_key = parse_connection_str(conn_str)
return cls(endpoint, AzureKeyCredential(access_key), **kwargs)


class MessageTemplateClient(MessageTemplateClientGenerated):
"""A client to interact with the AzureCommunicationService Messaging service.

This client provides Advanced Messaging.

:param str endpoint:
The endpoint of the Azure Communication resource.
:param Union[TokenCredential, AsyncTokenCredential] credential:
The credentials with which to authenticate

:keyword api_version: Azure Communication Messages API version. Default value is "2024-02-01".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, endpoint: str, credential: Union[TokenCredential, AzureKeyCredential], **kwargs: Any) -> "None":
if not credential:
raise ValueError("credential can not be None")

try:
if not endpoint.lower().startswith("http"):
endpoint = "https://" + endpoint
except AttributeError:
raise ValueError("Host URL must be a string") # pylint: disable=raise-missing-from

parsed_url = urlparse(endpoint.rstrip("/"))
if not parsed_url.netloc:
raise ValueError("Invalid URL: {}".format(endpoint))

self._endpoint = endpoint
self._api_version = kwargs.pop("api_version", DEFAULT_VERSION)
self._authentication_policy = get_authentication_policy(endpoint, credential)
self._credential = credential
super().__init__(
self._endpoint,
self._credential,
authentication_policy=self._authentication_policy,
api_version=self._api_version,
**kwargs
)

@classmethod
def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "MessageTemplateClient":
"""Create MessageTemplateClient from a Connection String.

:param conn_str: Azure communication service connection string. Required.
:type conn_str: str
:return: instance of MessageTemplateClient
:rtype:
~azure.communication.messages.MessageTemplateClient
"""
endpoint, access_key = parse_connection_str(conn_str)
return cls(endpoint, AzureKeyCredential(access_key), **kwargs)


__all__: List[str] = [
"NotificationMessagesClient",
"MessageTemplateClient",
] # Add all objects you want publicly available to users at this package level
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level


def patch_sdk():
Expand Down
Loading