Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft committed May 30, 2024
1 parent 711412a commit 358de83
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
# --------------------------------------------------------------------------

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

__all__ = ["MultiapiServiceClient"]

try:
from ._patch import patch_sdk # type: ignore

patch_sdk()
except ImportError:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential


class MultiapiServiceClientConfiguration:
"""Configuration for MultiapiServiceClient.
Expand All @@ -29,32 +30,27 @@ class MultiapiServiceClientConfiguration:
:type credential: ~azure.core.credentials.TokenCredential
"""

def __init__(
self,
credential: "TokenCredential",
**kwargs: Any
):
def __init__(self, credential: "TokenCredential", **kwargs: Any):
if credential is None:
raise ValueError("Parameter 'credential' must not be None.")

self.credential = credential
self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default'])
kwargs.setdefault('sdk_moniker', 'azure-multiapi-sample/{}'.format(VERSION))
self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"])
kwargs.setdefault("sdk_moniker", "azure-multiapi-sample/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

def _configure(
self,
**kwargs: Any
):
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
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 ARMHttpLoggingPolicy(**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.authentication_policy = kwargs.get('authentication_policy')
def _configure(self, **kwargs: Any):
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
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 ARMHttpLoggingPolicy(**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.authentication_policy = kwargs.get("authentication_policy")
if self.credential and not self.authentication_policy:
self.authentication_policy = ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)
self.authentication_policy = ARMChallengeAuthenticationPolicy(
self.credential, *self.credential_scopes, **kwargs
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential


class _SDKClient(object):
def __init__(self, *args, **kwargs):
"""This is a fake class to support current implemetation of MultiApiClientMixin."
Will be removed in final version of multiapi azure-core based client
"""
pass


class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClientMixin, _SDKClient):
"""Service client for multiapi client testing.
Expand All @@ -54,28 +56,30 @@ class MultiapiServiceClient(MultiapiServiceClientOperationsMixin, MultiApiClient
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

DEFAULT_API_VERSION = '3.0.0'
DEFAULT_API_VERSION = "3.0.0"
_PROFILE_TAG = "azure.multiapi.sample.MultiapiServiceClient"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
'begin_test_lro': '1.0.0',
'begin_test_lro_and_paging': '1.0.0',
'test_one': '2.0.0',
}},
_PROFILE_TAG + " latest"
LATEST_PROFILE = ProfileDefinition(
{
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
"begin_test_lro": "1.0.0",
"begin_test_lro_and_paging": "1.0.0",
"test_one": "2.0.0",
}
},
_PROFILE_TAG + " latest",
)

def __init__(
self,
credential: "TokenCredential",
api_version: Optional[str]=None,
api_version: Optional[str] = None,
base_url: str = "http://localhost:3000",
profile: KnownProfiles=KnownProfiles.default,
profile: KnownProfiles = KnownProfiles.default,
**kwargs: Any
):
if api_version:
kwargs.setdefault('api_version', api_version)
kwargs.setdefault("api_version", api_version)
self._config = MultiapiServiceClientConfiguration(credential, **kwargs)
_policies = kwargs.pop("policies", None)
if _policies is None:
Expand All @@ -96,10 +100,7 @@ def __init__(
self._config.http_logging_policy,
]
self._client = ARMPipelineClient(base_url=base_url, policies=_policies, **kwargs)
super(MultiapiServiceClient, self).__init__(
api_version=api_version,
profile=profile
)
super(MultiapiServiceClient, self).__init__(api_version=api_version, profile=profile)

@classmethod
def _models_dict(cls, api_version):
Expand All @@ -109,62 +110,79 @@ def _models_dict(cls, api_version):
def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:
* 1.0.0: :mod:`v1.models<azure.multiapi.sample.v1.models>`
* 2.0.0: :mod:`v2.models<azure.multiapi.sample.v2.models>`
* 3.0.0: :mod:`v3.models<azure.multiapi.sample.v3.models>`
* 1.0.0: :mod:`v1.models<azure.multiapi.sample.v1.models>`
* 2.0.0: :mod:`v2.models<azure.multiapi.sample.v2.models>`
* 3.0.0: :mod:`v3.models<azure.multiapi.sample.v3.models>`
"""
if api_version == '1.0.0':
if api_version == "1.0.0":
from .v1 import models

return models
elif api_version == '2.0.0':
elif api_version == "2.0.0":
from .v2 import models

return models
elif api_version == '3.0.0':
elif api_version == "3.0.0":
from .v3 import models

return models
raise ValueError("API version {} is not available".format(api_version))

@property
def operation_group_one(self):
"""Instance depends on the API version:
* 1.0.0: :class:`OperationGroupOneOperations<azure.multiapi.sample.v1.operations.OperationGroupOneOperations>`
* 2.0.0: :class:`OperationGroupOneOperations<azure.multiapi.sample.v2.operations.OperationGroupOneOperations>`
* 3.0.0: :class:`OperationGroupOneOperations<azure.multiapi.sample.v3.operations.OperationGroupOneOperations>`
* 1.0.0: :class:`OperationGroupOneOperations<azure.multiapi.sample.v1.operations.OperationGroupOneOperations>`
* 2.0.0: :class:`OperationGroupOneOperations<azure.multiapi.sample.v2.operations.OperationGroupOneOperations>`
* 3.0.0: :class:`OperationGroupOneOperations<azure.multiapi.sample.v3.operations.OperationGroupOneOperations>`
"""
api_version = self._get_api_version('operation_group_one')
if api_version == '1.0.0':
api_version = self._get_api_version("operation_group_one")
if api_version == "1.0.0":
from .v1.operations import OperationGroupOneOperations as OperationClass
elif api_version == '2.0.0':
elif api_version == "2.0.0":
from .v2.operations import OperationGroupOneOperations as OperationClass
elif api_version == '3.0.0':
elif api_version == "3.0.0":
from .v3.operations import OperationGroupOneOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'operation_group_one'".format(api_version))
self._config.api_version = api_version
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)), api_version)
return OperationClass(
self._client,
self._config,
Serializer(self._models_dict(api_version)),
Deserializer(self._models_dict(api_version)),
api_version,
)

@property
def operation_group_two(self):
"""Instance depends on the API version:
* 2.0.0: :class:`OperationGroupTwoOperations<azure.multiapi.sample.v2.operations.OperationGroupTwoOperations>`
* 3.0.0: :class:`OperationGroupTwoOperations<azure.multiapi.sample.v3.operations.OperationGroupTwoOperations>`
* 2.0.0: :class:`OperationGroupTwoOperations<azure.multiapi.sample.v2.operations.OperationGroupTwoOperations>`
* 3.0.0: :class:`OperationGroupTwoOperations<azure.multiapi.sample.v3.operations.OperationGroupTwoOperations>`
"""
api_version = self._get_api_version('operation_group_two')
if api_version == '2.0.0':
api_version = self._get_api_version("operation_group_two")
if api_version == "2.0.0":
from .v2.operations import OperationGroupTwoOperations as OperationClass
elif api_version == '3.0.0':
elif api_version == "3.0.0":
from .v3.operations import OperationGroupTwoOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'operation_group_two'".format(api_version))
self._config.api_version = api_version
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)), api_version)
return OperationClass(
self._client,
self._config,
Serializer(self._models_dict(api_version)),
Deserializer(self._models_dict(api_version)),
api_version,
)

def close(self):
self._client.close()

def __enter__(self):
self._client.__enter__()
return self

def __exit__(self, *exc_details):
self._client.__exit__(*exc_details)
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
class MultiapiServiceClientOperationsMixin(object):

def begin_test_lro(
self,
product: Optional[Union[_models.Product, IO[bytes]]] = None,
**kwargs: Any
self, product: Optional[Union[_models.Product, IO[bytes]]] = None, **kwargs: Any
) -> LROPoller[_models.Product]:
"""Put in whatever shape of Product you want, will return a Product with id equal to 100.
Expand All @@ -34,8 +32,8 @@ def begin_test_lro(
:rtype: ~azure.core.polling.LROPoller[~azure.multiapi.sample.v1.models.Product]
:raises ~azure.core.exceptions.HttpResponseError:
"""
api_version = self._get_api_version('begin_test_lro')
if api_version == '1.0.0':
api_version = self._get_api_version("begin_test_lro")
if api_version == "1.0.0":
from .v1.operations import MultiapiServiceClientOperationsMixin as OperationClass
else:
raise ValueError("API version {} does not have operation 'begin_test_lro'".format(api_version))
Expand Down Expand Up @@ -66,8 +64,8 @@ def begin_test_lro_and_paging(
~azure.core.polling.LROPoller[~azure.core.paging.ItemPaged[~azure.multiapi.sample.v1.models.Product]]
:raises ~azure.core.exceptions.HttpResponseError:
"""
api_version = self._get_api_version('begin_test_lro_and_paging')
if api_version == '1.0.0':
api_version = self._get_api_version("begin_test_lro_and_paging")
if api_version == "1.0.0":
from .v1.operations import MultiapiServiceClientOperationsMixin as OperationClass
else:
raise ValueError("API version {} does not have operation 'begin_test_lro_and_paging'".format(api_version))
Expand Down Expand Up @@ -99,12 +97,12 @@ def test_different_calls( # pylint: disable=inconsistent-return-statements
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
api_version = self._get_api_version('test_different_calls')
if api_version == '1.0.0':
api_version = self._get_api_version("test_different_calls")
if api_version == "1.0.0":
from .v1.operations import MultiapiServiceClientOperationsMixin as OperationClass
elif api_version == '2.0.0':
elif api_version == "2.0.0":
from .v2.operations import MultiapiServiceClientOperationsMixin as OperationClass
elif api_version == '3.0.0':
elif api_version == "3.0.0":
from .v3.operations import MultiapiServiceClientOperationsMixin as OperationClass
else:
raise ValueError("API version {} does not have operation 'test_different_calls'".format(api_version))
Expand All @@ -115,13 +113,12 @@ def test_different_calls( # pylint: disable=inconsistent-return-statements
mixin_instance._serialize = Serializer(self._models_dict(api_version))
mixin_instance._serialize.client_side_validation = False
mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
return mixin_instance.test_different_calls(greeting_in_english, greeting_in_chinese, greeting_in_french, **kwargs)
return mixin_instance.test_different_calls(
greeting_in_english, greeting_in_chinese, greeting_in_french, **kwargs
)

def test_one( # pylint: disable=inconsistent-return-statements
self,
id: int,
message: Optional[str] = None,
**kwargs: Any
self, id: int, message: Optional[str] = None, **kwargs: Any
) -> None:
"""TestOne should be in an FirstVersionOperationsMixin.
Expand All @@ -133,10 +130,10 @@ def test_one( # pylint: disable=inconsistent-return-statements
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
api_version = self._get_api_version('test_one')
if api_version == '1.0.0':
api_version = self._get_api_version("test_one")
if api_version == "1.0.0":
from .v1.operations import MultiapiServiceClientOperationsMixin as OperationClass
elif api_version == '2.0.0':
elif api_version == "2.0.0":
from .v2.operations import MultiapiServiceClientOperationsMixin as OperationClass
else:
raise ValueError("API version {} does not have operation 'test_one'".format(api_version))
Expand All @@ -149,18 +146,15 @@ def test_one( # pylint: disable=inconsistent-return-statements
mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
return mixin_instance.test_one(id, message, **kwargs)

def test_paging(
self,
**kwargs: Any
) -> Iterable["_models.ModelThree"]:
def test_paging(self, **kwargs: Any) -> Iterable["_models.ModelThree"]:
"""Returns ModelThree with optionalProperty 'paged'.
:return: An iterator like instance of either ModelThree or the result of cls(response)
:rtype: ~azure.core.paging.ItemPaged[~azure.multiapi.sample.v3.models.ModelThree]
:raises ~azure.core.exceptions.HttpResponseError:
"""
api_version = self._get_api_version('test_paging')
if api_version == '3.0.0':
api_version = self._get_api_version("test_paging")
if api_version == "3.0.0":
from .v3.operations import MultiapiServiceClientOperationsMixin as OperationClass
else:
raise ValueError("API version {} does not have operation 'test_paging'".format(api_version))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
def as_dict(
self,
keep_readonly: bool = True,
key_transformer: Callable[
[str, Dict[str, Any], Any], Any
] = attribute_transformer,
key_transformer: Callable[[str, Dict[str, Any], Any], Any] = attribute_transformer,
**kwargs: Any
) -> JSON:
"""Return a dict that can be serialized using json.dump.
Expand Down Expand Up @@ -540,7 +538,7 @@ class Serializer(object):
"multiple": lambda x, y: x % y != 0,
}

def __init__(self, classes: Optional[Mapping[str, type]]=None):
def __init__(self, classes: Optional[Mapping[str, type]] = None):
self.serialize_type = {
"iso-8601": Serializer.serialize_iso,
"rfc-1123": Serializer.serialize_rfc,
Expand Down Expand Up @@ -748,7 +746,7 @@ 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]
do_quote = not kwargs.get('skip_quote', False)
do_quote = not kwargs.get("skip_quote", False)
return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs)

# Not a list, regular serialization
Expand Down Expand Up @@ -907,12 +905,8 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
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 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]
Expand Down Expand Up @@ -1369,7 +1363,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: Optional[Mapping[str, type]]=None):
def __init__(self, classes: Optional[Mapping[str, type]] = None):
self.deserialize_type = {
"iso-8601": Deserializer.deserialize_iso,
"rfc-1123": Deserializer.deserialize_rfc,
Expand Down
Loading

0 comments on commit 358de83

Please sign in to comment.