forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AutoRelease] t2-network-2023-06-26-52251(can only be merged by SDK o…
…wner) (Azure#30882) * code and test * update * update --------- Co-authored-by: PythonSdkPipelines <PythonSdkPipelines> Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
- Loading branch information
Showing
7 changed files
with
721 additions
and
710 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
310 changes: 155 additions & 155 deletions
310
sdk/network/azure-mgmt-network/azure/mgmt/network/_client.py
Large diffs are not rendered by default.
Oops, something went wrong.
54 changes: 25 additions & 29 deletions
54
sdk/network/azure-mgmt-network/azure/mgmt/network/_validation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,49 @@ | ||
|
||
|
||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) Python Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
from typing import Optional, Dict, List | ||
import functools | ||
|
||
|
||
class api_version_validation: | ||
def __init__( | ||
self, | ||
*, | ||
api_versions: Optional[List[str]] = None, | ||
params: Optional[Dict[str, List[str]]] = None, | ||
): | ||
self.api_versions = api_versions or [] | ||
self.params = params or {} | ||
def api_version_validation(**kwargs): | ||
params_valid_on = kwargs.pop("params_valid_on", {}) | ||
method_valid_on = kwargs.pop("method_valid_on", {}) | ||
|
||
def __call__(self, func): | ||
api_versions = self.api_versions | ||
params = self.params | ||
def wrapper(self, *args, **kwargs): | ||
def decorator(func): | ||
@functools.wraps(func) | ||
def wrapper(*args, **kwargs): | ||
func_name = func.__name__ | ||
if hasattr(self, "_get_api_version"): | ||
client_api_version = self._get_api_version(func_name) | ||
else: | ||
client_api_version = self._api_version | ||
if api_versions and client_api_version not in api_versions: | ||
try: | ||
client = args[0] | ||
client_api_version = client._get_api_version(func_name) # pylint: disable=protected-access | ||
except AttributeError: | ||
client_api_version = client._api_version # pylint: disable=protected-access | ||
|
||
if method_valid_on and client_api_version not in method_valid_on: | ||
raise ValueError( | ||
f"'{func_name}' is not available in API version " | ||
f"{client_api_version}. Pass service API version {api_versions[0]} or newer to your client." | ||
f"{client_api_version}. All valid API version are {', '.join(method_valid_on)}." | ||
) | ||
unsupported = [ | ||
parameter | ||
for parameter, api_versions in params.items() | ||
|
||
unsupported = { | ||
parameter: ", ".join(api_versions) | ||
for parameter, api_versions in params_valid_on.items() | ||
if parameter in kwargs and client_api_version not in api_versions | ||
] | ||
} | ||
if unsupported: | ||
raise ValueError( | ||
"".join( | ||
[ | ||
f"'{param}' is not available in API version {client_api_version}. " | ||
f"Use service API version {params[param][0]} or newer.\n" | ||
for param, version in unsupported | ||
f"All valid API version are {versions} \n" | ||
for param, versions in unsupported.items() | ||
] | ||
) | ||
) | ||
return func(self, *args, **kwargs) | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator |
Oops, something went wrong.