Skip to content

Commit

Permalink
CodeGen from PR 21878 in Azure/azure-rest-api-specs
Browse files Browse the repository at this point in the history
Merge 26dd4b4255afc26e4b3ac3ba05d58f5a87afe49a into a1ac491c7a753e63710b5cf38d8c10211a5ae4e6
  • Loading branch information
SDKAuto committed Dec 13, 2022
1 parent d111b55 commit 654f6f3
Show file tree
Hide file tree
Showing 1,435 changed files with 41,287 additions and 34,674 deletions.
6 changes: 3 additions & 3 deletions sdk/sql/azure-mgmt-sql/_meta.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"commit": "8a20cee044fafde7ae0364edab45a577aa80d20f",
"commit": "c3996aef95fef29d744f90e7d0c2c16090d34294",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"autorest": "3.9.2",
"use": [
"@autorest/[email protected].1",
"@autorest/[email protected].7",
"@autorest/[email protected]"
],
"autorest_command": "autorest specification/sql/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/[email protected].1 --use=@autorest/[email protected] --version=3.9.2 --version-tolerant=False",
"autorest_command": "autorest specification/sql/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/[email protected].7 --use=@autorest/[email protected] --version=3.9.2 --version-tolerant=False",
"readme": "specification/sql/resource-manager/readme.md"
}
2 changes: 1 addition & 1 deletion sdk/sql/azure-mgmt-sql/azure/mgmt/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

try:
from ._patch import __all__ as _patch_all
from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
from ._patch import * # pylint: disable=unused-wildcard-import
except ImportError:
_patch_all = []
from ._patch import patch_sdk as _patch_sdk
Expand Down
5 changes: 1 addition & 4 deletions sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs
kwargs.setdefault("sdk_moniker", "mgmt-sql/{}".format(VERSION))
self._configure(**kwargs)

def _configure(
self, **kwargs # type: Any
):
# type: (...) -> None
def _configure(self, **kwargs: Any) -> None:
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)
Expand Down
93 changes: 45 additions & 48 deletions sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# --------------------------------------------------------------------------

# pylint: skip-file
# pyright: reportUnnecessaryTypeIgnoreComment=false

from base64 import b64decode, b64encode
import calendar
Expand All @@ -37,24 +38,22 @@
import re
import sys
import codecs
from typing import Optional, Union, AnyStr, IO, Mapping

try:
from urllib import quote # type: ignore
except ImportError:
from urllib.parse import quote # type: ignore
from urllib.parse import quote
import xml.etree.ElementTree as ET

import isodate
import isodate # type: ignore

from typing import Dict, Any, cast, TYPE_CHECKING
from typing import Dict, Any, cast

from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback

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

if TYPE_CHECKING:
from typing import Optional, Union, AnyStr, IO, Mapping


class RawDeserializer:

Expand All @@ -65,8 +64,7 @@ class RawDeserializer:
CONTEXT_NAME = "deserialized_data"

@classmethod
def deserialize_from_text(cls, data, content_type=None):
# type: (Optional[Union[AnyStr, IO]], Optional[str]) -> Any
def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type: Optional[str] = None) -> Any:
"""Decode data according to content-type.
Accept a stream of data as well, but will be load at once in memory for now.
Expand Down Expand Up @@ -132,8 +130,7 @@ def _json_attemp(data):
raise DeserializationError("Cannot deserialize content-type: {}".format(content_type))

@classmethod
def deserialize_from_http_generics(cls, body_bytes, headers):
# type: (Optional[Union[AnyStr, IO]], Mapping) -> Any
def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]], headers: Mapping) -> Any:
"""Deserialize from HTTP response.
Use bytes and headers to NOT use any requests/aiohttp or whatever
Expand All @@ -160,8 +157,8 @@ def deserialize_from_http_generics(cls, body_bytes, headers):
basestring # type: ignore
unicode_str = unicode # type: ignore
except NameError:
basestring = str # type: ignore
unicode_str = str # type: ignore
basestring = str
unicode_str = str

_LOGGER = logging.getLogger(__name__)

Expand All @@ -188,7 +185,7 @@ def dst(self, dt):


try:
from datetime import timezone as _FixedOffset
from datetime import timezone as _FixedOffset # type: ignore
except ImportError: # Python 2.7

class _FixedOffset(datetime.tzinfo): # type: ignore
Expand Down Expand Up @@ -219,7 +216,7 @@ def __getinitargs__(self):
try:
from datetime import timezone

TZ_UTC = timezone.utc # type: ignore
TZ_UTC = timezone.utc
except ImportError:
TZ_UTC = UTC() # type: ignore

Expand Down Expand Up @@ -276,9 +273,9 @@ class Model(object):
serialization and deserialization.
"""

_subtype_map = {} # type: Dict[str, Dict[str, Any]]
_attribute_map = {} # type: Dict[str, Dict[str, Any]]
_validation = {} # type: Dict[str, Dict[str, Any]]
_subtype_map: Dict[str, Dict[str, Any]] = {}
_attribute_map: Dict[str, Dict[str, Any]] = {}
_validation: Dict[str, Dict[str, Any]] = {}

def __init__(self, **kwargs):
self.additional_properties = {}
Expand Down Expand Up @@ -310,7 +307,7 @@ def enable_additional_properties_sending(cls):
@classmethod
def is_xml_model(cls):
try:
cls._xml_map
cls._xml_map # type: ignore
except AttributeError:
return False
return True
Expand All @@ -319,7 +316,7 @@ def is_xml_model(cls):
def _create_xml_node(cls):
"""Create XML node."""
try:
xml_map = cls._xml_map
xml_map = cls._xml_map # type: ignore
except AttributeError:
xml_map = {}

Expand Down Expand Up @@ -453,7 +450,7 @@ def _classify(cls, response, objects):
return cls
flatten_mapping_type = cls._flatten_subtype(subtype_key, objects)
try:
return objects[flatten_mapping_type[subtype_value]]
return objects[flatten_mapping_type[subtype_value]] # type: ignore
except KeyError:
_LOGGER.warning(
"Subtype value %s has no mapping, use base class %s.",
Expand Down Expand Up @@ -606,13 +603,13 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
if xml_ns:
ET.register_namespace(xml_prefix, xml_ns)
xml_name = "{}{}".format(xml_ns, xml_name)
serialized.set(xml_name, new_attr)
serialized.set(xml_name, new_attr) # type: ignore
continue
if xml_desc.get("text", False):
serialized.text = new_attr
serialized.text = new_attr # type: ignore
continue
if isinstance(new_attr, list):
serialized.extend(new_attr)
serialized.extend(new_attr) # type: ignore
elif isinstance(new_attr, ET.Element):
# If the down XML has no XML/Name, we MUST replace the tag with the local tag. But keeping the namespaces.
if "name" not in getattr(orig_attr, "_xml_map", {}):
Expand All @@ -621,23 +618,23 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
new_attr.tag = "}".join([splitted_tag[0], xml_name])
else:
new_attr.tag = xml_name
serialized.append(new_attr)
serialized.append(new_attr) # type: ignore
else: # That's a basic type
# Integrate namespace if necessary
local_node = _create_xml_node(xml_name, xml_prefix, xml_ns)
local_node.text = unicode_str(new_attr)
serialized.append(local_node)
serialized.append(local_node) # type: ignore
else: # JSON
for k in reversed(keys):
for k in reversed(keys): # type: ignore
unflattened = {k: new_attr}
new_attr = unflattened

_new_attr = new_attr
_serialized = serialized
for k in keys:
for k in keys: # type: ignore
if k not in _serialized:
_serialized.update(_new_attr)
_new_attr = _new_attr[k]
_serialized.update(_new_attr) # type: ignore
_new_attr = _new_attr[k] # type: ignore
_serialized = _serialized[k]
except ValueError:
continue
Expand Down Expand Up @@ -675,7 +672,7 @@ def body(self, data, data_type, **kwargs):
# We're not able to deal with additional properties for now.
deserializer.additional_properties_detection = False
if is_xml_model_serialization:
deserializer.key_extractors = [
deserializer.key_extractors = [ # type: ignore
attribute_key_case_insensitive_extractor,
]
else:
Expand Down Expand Up @@ -843,7 +840,7 @@ def serialize_unicode(cls, data):
pass

try:
if isinstance(data, unicode):
if isinstance(data, unicode): # type: ignore
# Don't change it, JSON and XML ElementTree are totally able
# to serialize correctly u'' strings
return data
Expand Down Expand Up @@ -1001,10 +998,10 @@ def serialize_enum(attr, enum_obj=None):
except AttributeError:
result = attr
try:
enum_obj(result)
enum_obj(result) # type: ignore
return result
except ValueError:
for enum_value in enum_obj:
for enum_value in enum_obj: # type: ignore
if enum_value.value.lower() == str(attr).lower():
return enum_value.value
error = "{!r} is not valid value for enum {!r}"
Expand Down Expand Up @@ -1416,7 +1413,7 @@ def _deserialize(self, target_obj, data):
if data is None:
return data
try:
attributes = response._attribute_map
attributes = response._attribute_map # type: ignore
d_attrs = {}
for attr, attr_desc in attributes.items():
# Check empty string. If it's not empty, someone has a real "additionalProperties"...
Expand Down Expand Up @@ -1444,7 +1441,7 @@ def _deserialize(self, target_obj, data):
value = self.deserialize_data(raw_value, attr_desc["type"])
d_attrs[attr] = value
except (AttributeError, TypeError, KeyError) as err:
msg = "Unable to deserialize to object: " + class_name
msg = "Unable to deserialize to object: " + class_name # type: ignore
raise_with_traceback(DeserializationError, msg, err)
else:
additional_properties = self._build_additional_properties(attributes, data)
Expand Down Expand Up @@ -1543,7 +1540,7 @@ def _unpack_content(raw_data, content_type=None):
return RawDeserializer.deserialize_from_http_generics(raw_data.text, raw_data.headers)

if isinstance(raw_data, (basestring, bytes)) or hasattr(raw_data, "read"):
return RawDeserializer.deserialize_from_text(raw_data, content_type)
return RawDeserializer.deserialize_from_text(raw_data, content_type) # type: ignore
return raw_data

def _instantiate_model(self, response, attrs, additional_properties=None):
Expand All @@ -1565,7 +1562,7 @@ def _instantiate_model(self, response, attrs, additional_properties=None):
response_obj.additional_properties = additional_properties
return response_obj
except TypeError as err:
msg = "Unable to deserialize {} into model {}. ".format(kwargs, response)
msg = "Unable to deserialize {} into model {}. ".format(kwargs, response) # type: ignore
raise DeserializationError(msg + str(err))
else:
try:
Expand Down Expand Up @@ -1747,7 +1744,7 @@ def deserialize_unicode(data):

# Consider this is real string
try:
if isinstance(data, unicode):
if isinstance(data, unicode): # type: ignore
return data
except NameError:
return str(data)
Expand Down Expand Up @@ -1798,7 +1795,7 @@ def deserialize_bytearray(attr):
"""
if isinstance(attr, ET.Element):
attr = attr.text
return bytearray(b64decode(attr))
return bytearray(b64decode(attr)) # type: ignore

@staticmethod
def deserialize_base64(attr):
Expand All @@ -1810,8 +1807,8 @@ def deserialize_base64(attr):
"""
if isinstance(attr, ET.Element):
attr = attr.text
padding = "=" * (3 - (len(attr) + 3) % 4)
attr = attr + padding
padding = "=" * (3 - (len(attr) + 3) % 4) # type: ignore
attr = attr + padding # type: ignore
encoded = attr.replace("-", "+").replace("_", "/")
return b64decode(encoded)

Expand All @@ -1826,7 +1823,7 @@ def deserialize_decimal(attr):
if isinstance(attr, ET.Element):
attr = attr.text
try:
return decimal.Decimal(attr)
return decimal.Decimal(attr) # type: ignore
except decimal.DecimalException as err:
msg = "Invalid decimal {}".format(attr)
raise_with_traceback(DeserializationError, msg, err)
Expand All @@ -1841,7 +1838,7 @@ def deserialize_long(attr):
"""
if isinstance(attr, ET.Element):
attr = attr.text
return _long_type(attr)
return _long_type(attr) # type: ignore

@staticmethod
def deserialize_duration(attr):
Expand Down Expand Up @@ -1871,7 +1868,7 @@ def deserialize_date(attr):
"""
if isinstance(attr, ET.Element):
attr = attr.text
if re.search(r"[^\W\d_]", attr, re.I + re.U):
if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore
raise DeserializationError("Date must have only digits and -. Received: %s" % attr)
# This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
return isodate.parse_date(attr, defaultmonth=None, defaultday=None)
Expand All @@ -1886,7 +1883,7 @@ def deserialize_time(attr):
"""
if isinstance(attr, ET.Element):
attr = attr.text
if re.search(r"[^\W\d_]", attr, re.I + re.U):
if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore
raise DeserializationError("Date must have only digits and -. Received: %s" % attr)
return isodate.parse_time(attr)

Expand All @@ -1901,7 +1898,7 @@ def deserialize_rfc(attr):
if isinstance(attr, ET.Element):
attr = attr.text
try:
parsed_date = email.utils.parsedate_tz(attr)
parsed_date = email.utils.parsedate_tz(attr) # type: ignore
date_obj = datetime.datetime(
*parsed_date[:6], tzinfo=_FixedOffset(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60))
)
Expand All @@ -1924,7 +1921,7 @@ def deserialize_iso(attr):
if isinstance(attr, ET.Element):
attr = attr.text
try:
attr = attr.upper()
attr = attr.upper() # type: ignore
match = Deserializer.valid_date.match(attr)
if not match:
raise ValueError("Invalid datetime string: " + attr)
Expand Down Expand Up @@ -1960,7 +1957,7 @@ def deserialize_unix(attr):
:raises: DeserializationError if format invalid
"""
if isinstance(attr, ET.Element):
attr = int(attr.text)
attr = int(attr.text) # type: ignore
try:
date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC)
except ValueError as err:
Expand Down
Loading

0 comments on commit 654f6f3

Please sign in to comment.