Skip to content

Commit

Permalink
CodeGen from PR 26953 in Azure/azure-rest-api-specs
Browse files Browse the repository at this point in the history
Merge 25687e6545c3cb71ca0422ea8e17997de4f75b86 into 907b79c0a6a660826e54dc1f16ea14b831b201d2
  • Loading branch information
SDKAuto committed Jan 10, 2024
1 parent da54de9 commit c87782b
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 118 deletions.
8 changes: 4 additions & 4 deletions sdk/sphere/azure-mgmt-sphere/_meta.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"commit": "23d88533ddfde4d1565a897fe95d42fb0d9333e5",
"commit": "992856006df06298e708007f0106f811ee15210f",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"autorest": "3.9.6",
"autorest": "3.9.7",
"use": [
"@autorest/python@6.6.0",
"@autorest/python@6.7.1",
"@autorest/[email protected]"
],
"autorest_command": "autorest specification/sphere/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/home/vsts/work/1/azure-sdk-for-python/sdk --use=@autorest/python@6.6.0 --use=@autorest/[email protected] --version=3.9.6 --version-tolerant=False",
"autorest_command": "autorest specification/sphere/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/mnt/vss/_work/1/s/azure-sdk-for-python/sdk --use=@autorest/python@6.7.1 --use=@autorest/[email protected] --version=3.9.7 --version-tolerant=False",
"readme": "specification/sphere/resource-manager/readme.md"
}
26 changes: 18 additions & 8 deletions sdk/sphere/azure-mgmt-sphere/azure/mgmt/sphere/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,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 Down Expand Up @@ -741,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 @@ -749,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 @@ -891,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 @@ -903,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 @@ -950,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
14 changes: 0 additions & 14 deletions sdk/sphere/azure-mgmt-sphere/azure/mgmt/sphere/_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import List, cast

from azure.core.pipeline.transport import HttpRequest


Expand All @@ -16,15 +14,3 @@ def _convert_request(request, files=None):
if files:
request.set_formdata_body(files)
return request


def _format_url_section(template, **kwargs):
components = template.split("/")
while components:
try:
return template.format(**kwargs)
except KeyError as key:
# Need the cast, as for some reasons "split" is typed as list[str | Any]
formatted_components = cast(List[str], template.split("/"))
components = [c for c in formatted_components if "{}".format(key.args[0]) not in c]
template = "/".join(components)
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def get(self, resource_group_name: str, catalog_name: str, image_name: str
:type resource_group_name: str
:param catalog_name: Name of catalog. Required.
:type catalog_name: str
:param image_name: Image name. Use .default for image creation. Required.
:param image_name: Image name. Use an image GUID for GA versions of the API. Required.
:type image_name: str
:keyword callable cls: A custom type or function that will be passed the direct response
:return: Image or the result of cls(response)
Expand Down Expand Up @@ -333,7 +333,7 @@ async def begin_create_or_update(
:type resource_group_name: str
:param catalog_name: Name of catalog. Required.
:type catalog_name: str
:param image_name: Image name. Use .default for image creation. Required.
:param image_name: Image name. Use an image GUID for GA versions of the API. Required.
:type image_name: str
:param resource: Resource create parameters. Required.
:type resource: ~azure.mgmt.sphere.models.Image
Expand Down Expand Up @@ -371,7 +371,7 @@ async def begin_create_or_update(
:type resource_group_name: str
:param catalog_name: Name of catalog. Required.
:type catalog_name: str
:param image_name: Image name. Use .default for image creation. Required.
:param image_name: Image name. Use an image GUID for GA versions of the API. Required.
:type image_name: str
:param resource: Resource create parameters. Required.
:type resource: IO
Expand Down Expand Up @@ -407,7 +407,7 @@ async def begin_create_or_update(
:type resource_group_name: str
:param catalog_name: Name of catalog. Required.
:type catalog_name: str
:param image_name: Image name. Use .default for image creation. Required.
:param image_name: Image name. Use an image GUID for GA versions of the API. Required.
:type image_name: str
:param resource: Resource create parameters. Is either a Image type or a IO type. Required.
:type resource: ~azure.mgmt.sphere.models.Image or IO
Expand Down Expand Up @@ -543,7 +543,7 @@ async def begin_delete(
:type resource_group_name: str
:param catalog_name: Name of catalog. Required.
:type catalog_name: str
:param image_name: Image name. Use .default for image creation. Required.
:param image_name: Image name. Use an image GUID for GA versions of the API. Required.
:type image_name: str
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ._models_py3 import CertificateProperties
from ._models_py3 import ClaimDevicesRequest
from ._models_py3 import CountDeviceResponse
from ._models_py3 import CountDevicesResponse
from ._models_py3 import CountElementsResponse
from ._models_py3 import Deployment
from ._models_py3 import DeploymentListResult
Expand All @@ -32,7 +33,6 @@
from ._models_py3 import GenerateCapabilityImageRequest
from ._models_py3 import Image
from ._models_py3 import ImageListResult
from ._models_py3 import ImageUploadRequestBody
from ._models_py3 import ListDeviceGroupsRequest
from ._models_py3 import Operation
from ._models_py3 import OperationDisplay
Expand Down Expand Up @@ -60,6 +60,7 @@
from ._azure_sphere_mgmt_client_enums import ProvisioningState
from ._azure_sphere_mgmt_client_enums import RegionalDataBoundary
from ._azure_sphere_mgmt_client_enums import UpdatePolicy
from ._azure_sphere_mgmt_client_enums import Versions
from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
from ._patch import patch_sdk as _patch_sdk
Expand All @@ -74,6 +75,7 @@
"CertificateProperties",
"ClaimDevicesRequest",
"CountDeviceResponse",
"CountDevicesResponse",
"CountElementsResponse",
"Deployment",
"DeploymentListResult",
Expand All @@ -91,7 +93,6 @@
"GenerateCapabilityImageRequest",
"Image",
"ImageListResult",
"ImageUploadRequestBody",
"ListDeviceGroupsRequest",
"Operation",
"OperationDisplay",
Expand All @@ -118,6 +119,7 @@
"ProvisioningState",
"RegionalDataBoundary",
"UpdatePolicy",
"Versions",
]
__all__.extend([p for p in _patch_all if p not in __all__])
_patch_sdk()
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class OSFeedType(str, Enum, metaclass=CaseInsensitiveEnumMeta):


class ProvisioningState(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""Provisioning state of the resource."""
"""Provisioning state of resource."""

SUCCEEDED = "Succeeded"
"""Resource has been created."""
Expand Down Expand Up @@ -163,3 +163,12 @@ class UpdatePolicy(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""Update all policy."""
NO3_RD_PARTY_APP_UPDATES = "No3rdPartyAppUpdates"
"""No update for 3rd party app policy."""


class Versions(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""Azure Sphere API versions."""

V2022_09_01 = "2022-09-01-preview"
"""Public preview API version."""
V2024_04_01 = "2024-04-01"
"""Initial GA API version."""
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,31 @@ def __init__(self, *, value: int, **kwargs: Any) -> None:


class CountDeviceResponse(CountElementsResponse):
"""Response to the action call for count devices in a catalog (preview API).
All required parameters must be populated in order to send to Azure.
:ivar value: Number of children resources in parent resource. Required.
:vartype value: int
"""

_validation = {
"value": {"required": True},
}

_attribute_map = {
"value": {"key": "value", "type": "int"},
}

def __init__(self, *, value: int, **kwargs: Any) -> None:
"""
:keyword value: Number of children resources in parent resource. Required.
:paramtype value: int
"""
super().__init__(value=value, **kwargs)


class CountDevicesResponse(CountElementsResponse):
"""Response to the action call for count devices in a catalog.
All required parameters must be populated in order to send to Azure.
Expand Down Expand Up @@ -1305,32 +1330,6 @@ def __init__(self, *, value: List["_models.Image"], next_link: Optional[str] = N
self.next_link = next_link


class ImageUploadRequestBody(_serialization.Model):
"""Image upload request body.
All required parameters must be populated in order to send to Azure.
:ivar images: . Required.
:vartype images: str
"""

_validation = {
"images": {"required": True},
}

_attribute_map = {
"images": {"key": "images", "type": "str"},
}

def __init__(self, *, images: str, **kwargs: Any) -> None:
"""
:keyword images: . Required.
:paramtype images: str
"""
super().__init__(**kwargs)
self.images = images


class ListDeviceGroupsRequest(_serialization.Model):
"""Request of the action to list device groups for a catalog.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from .. import models as _models
from .._serialization import Serializer
from .._vendor import _convert_request, _format_url_section
from .._vendor import _convert_request

T = TypeVar("T")
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
Expand All @@ -52,7 +52,7 @@ def build_list_by_subscription_request(subscription_id: str, **kwargs: Any) -> H
"subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str", min_length=1),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -82,7 +82,7 @@ def build_list_by_resource_group_request(resource_group_name: str, subscription_
),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -113,7 +113,7 @@ def build_get_request(resource_group_name: str, catalog_name: str, subscription_
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -147,7 +147,7 @@ def build_create_or_update_request(
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -183,7 +183,7 @@ def build_update_request(
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -218,7 +218,7 @@ def build_delete_request(
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -251,7 +251,7 @@ def build_count_devices_request(
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -292,7 +292,7 @@ def build_list_deployments_request(
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -342,7 +342,7 @@ def build_list_device_groups_request(
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -393,7 +393,7 @@ def build_list_device_insights_request(
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down Expand Up @@ -442,7 +442,7 @@ def build_list_devices_request(
"catalogName": _SERIALIZER.url("catalog_name", catalog_name, "str", pattern=r"^[A-Za-z0-9_-]{1,50}$"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url: str = _url.format(**path_format_arguments) # type: ignore

# Construct parameters
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
Expand Down
Loading

0 comments on commit c87782b

Please sign in to comment.