@autorest/python 6.9.4 → 6.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/_utils.py +2 -2
- package/autorest/codegen/__init__.py +250 -138
- package/autorest/codegen/_utils.py +2 -2
- package/autorest/codegen/models/__init__.py +7 -7
- package/autorest/codegen/models/base.py +5 -2
- package/autorest/codegen/models/client.py +31 -24
- package/autorest/codegen/models/combined_type.py +1 -1
- package/autorest/codegen/models/constant_type.py +1 -1
- package/autorest/codegen/models/credential_types.py +33 -23
- package/autorest/codegen/models/dictionary_type.py +1 -1
- package/autorest/codegen/models/enum_type.py +2 -2
- package/autorest/codegen/models/imports.py +71 -3
- package/autorest/codegen/models/list_type.py +1 -1
- package/autorest/codegen/models/lro_operation.py +2 -2
- package/autorest/codegen/models/model_type.py +1 -1
- package/autorest/codegen/models/operation.py +25 -17
- package/autorest/codegen/models/operation_group.py +2 -2
- package/autorest/codegen/models/paging_operation.py +13 -5
- package/autorest/codegen/models/parameter.py +1 -1
- package/autorest/codegen/models/primitive_types.py +17 -13
- package/autorest/codegen/models/property.py +1 -1
- package/autorest/codegen/models/request_builder.py +8 -6
- package/autorest/codegen/models/response.py +26 -14
- package/autorest/codegen/serializers/__init__.py +5 -0
- package/autorest/codegen/serializers/base_serializer.py +21 -0
- package/autorest/codegen/serializers/builder_serializer.py +33 -19
- package/autorest/codegen/serializers/client_serializer.py +20 -5
- package/autorest/codegen/serializers/enum_serializer.py +5 -8
- package/autorest/codegen/serializers/general_serializer.py +19 -23
- package/autorest/codegen/serializers/model_serializer.py +5 -9
- package/autorest/codegen/serializers/operation_groups_serializer.py +4 -5
- package/autorest/codegen/serializers/patch_serializer.py +4 -8
- package/autorest/codegen/serializers/request_builders_serializer.py +4 -4
- package/autorest/codegen/serializers/sample_serializer.py +11 -9
- package/autorest/codegen/serializers/types_serializer.py +3 -8
- package/autorest/codegen/templates/config.py.jinja2 +3 -1
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/model_base.py.jinja2 +4 -4
- package/autorest/codegen/templates/packaging_templates/LICENSE.jinja2 +1 -1
- package/autorest/codegen/templates/packaging_templates/README.md.jinja2 +3 -1
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +7 -3
- package/autorest/codegen/templates/serialization.py.jinja2 +17 -18
- package/autorest/m4reformatter/__init__.py +1 -1
- package/autorest/multiapi/models/imports.py +1 -1
- package/autorest/multiapi/serializers/__init__.py +4 -1
- package/autorest/preprocess/__init__.py +1 -9
- package/package.json +1 -1
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
from typing import List
|
|
7
7
|
from abc import ABC, abstractmethod
|
|
8
8
|
|
|
9
|
-
from
|
|
10
|
-
from ..models import ModelType, CodeModel, Property, ConstantType, EnumValue
|
|
9
|
+
from ..models import ModelType, Property, ConstantType, EnumValue
|
|
11
10
|
from ..models.imports import FileImport, TypingSection, MsrestImportType, ImportType
|
|
12
11
|
from .import_serializer import FileImportSerializer
|
|
12
|
+
from .base_serializer import BaseSerializer
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def _documentation_string(
|
|
@@ -28,11 +28,7 @@ def _documentation_string(
|
|
|
28
28
|
return retval
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
class _ModelSerializer(ABC):
|
|
32
|
-
def __init__(self, code_model: CodeModel, env: Environment) -> None:
|
|
33
|
-
self.code_model = code_model
|
|
34
|
-
self.env = env
|
|
35
|
-
|
|
31
|
+
class _ModelSerializer(BaseSerializer, ABC):
|
|
36
32
|
@abstractmethod
|
|
37
33
|
def imports(self) -> FileImport:
|
|
38
34
|
...
|
|
@@ -133,7 +129,7 @@ class _ModelSerializer(ABC):
|
|
|
133
129
|
|
|
134
130
|
class MsrestModelSerializer(_ModelSerializer):
|
|
135
131
|
def imports(self) -> FileImport:
|
|
136
|
-
file_import =
|
|
132
|
+
file_import = self.init_file_import()
|
|
137
133
|
file_import.add_msrest_import(
|
|
138
134
|
relative_path="..",
|
|
139
135
|
msrest_import_type=MsrestImportType.Module,
|
|
@@ -202,7 +198,7 @@ class MsrestModelSerializer(_ModelSerializer):
|
|
|
202
198
|
|
|
203
199
|
class DpgModelSerializer(_ModelSerializer):
|
|
204
200
|
def imports(self) -> FileImport:
|
|
205
|
-
file_import =
|
|
201
|
+
file_import = self.init_file_import()
|
|
206
202
|
file_import.add_submodule_import(
|
|
207
203
|
"..",
|
|
208
204
|
"_model_base",
|
|
@@ -10,7 +10,6 @@ from jinja2 import Environment
|
|
|
10
10
|
from ..models import (
|
|
11
11
|
CodeModel,
|
|
12
12
|
OperationGroup,
|
|
13
|
-
FileImport,
|
|
14
13
|
RequestBuilder,
|
|
15
14
|
OverloadedRequestBuilder,
|
|
16
15
|
Client,
|
|
@@ -20,9 +19,10 @@ from .builder_serializer import (
|
|
|
20
19
|
get_operation_serializer,
|
|
21
20
|
RequestBuilderSerializer,
|
|
22
21
|
)
|
|
22
|
+
from .base_serializer import BaseSerializer
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
class OperationGroupsSerializer:
|
|
25
|
+
class OperationGroupsSerializer(BaseSerializer):
|
|
26
26
|
def __init__(
|
|
27
27
|
self,
|
|
28
28
|
code_model: CodeModel,
|
|
@@ -31,9 +31,8 @@ class OperationGroupsSerializer:
|
|
|
31
31
|
async_mode: bool,
|
|
32
32
|
operation_group: Optional[OperationGroup] = None,
|
|
33
33
|
):
|
|
34
|
+
super().__init__(code_model, env)
|
|
34
35
|
self.clients = clients
|
|
35
|
-
self.code_model = code_model
|
|
36
|
-
self.env = env
|
|
37
36
|
self.async_mode = async_mode
|
|
38
37
|
self.operation_group = operation_group
|
|
39
38
|
|
|
@@ -57,7 +56,7 @@ class OperationGroupsSerializer:
|
|
|
57
56
|
if self.operation_group
|
|
58
57
|
else [og for client in self.clients for og in client.operation_groups]
|
|
59
58
|
)
|
|
60
|
-
imports =
|
|
59
|
+
imports = self.init_file_import()
|
|
61
60
|
for operation_group in operation_groups:
|
|
62
61
|
imports.merge(
|
|
63
62
|
operation_group.imports(
|
|
@@ -3,19 +3,15 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from jinja2 import Environment
|
|
7
6
|
from .import_serializer import FileImportSerializer
|
|
8
|
-
from ..models import
|
|
7
|
+
from ..models import ImportType
|
|
8
|
+
from .base_serializer import BaseSerializer
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class PatchSerializer:
|
|
12
|
-
def __init__(self, env: Environment, code_model: CodeModel) -> None:
|
|
13
|
-
self.env = env
|
|
14
|
-
self.code_model = code_model
|
|
15
|
-
|
|
11
|
+
class PatchSerializer(BaseSerializer):
|
|
16
12
|
def serialize(self) -> str:
|
|
17
13
|
template = self.env.get_template("patch.py.jinja2")
|
|
18
|
-
imports =
|
|
14
|
+
imports = self.init_file_import()
|
|
19
15
|
imports.add_submodule_import("typing", "List", ImportType.STDLIB)
|
|
20
16
|
return template.render(
|
|
21
17
|
code_model=self.code_model,
|
|
@@ -10,23 +10,23 @@ from ..models import FileImport
|
|
|
10
10
|
from .import_serializer import FileImportSerializer
|
|
11
11
|
from ..models import CodeModel, RequestBuilderType
|
|
12
12
|
from .builder_serializer import RequestBuilderSerializer
|
|
13
|
+
from .base_serializer import BaseSerializer
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
class RequestBuildersSerializer:
|
|
16
|
+
class RequestBuildersSerializer(BaseSerializer):
|
|
16
17
|
def __init__(
|
|
17
18
|
self,
|
|
18
19
|
code_model: CodeModel,
|
|
19
20
|
env: Environment,
|
|
20
21
|
request_builders: List[RequestBuilderType],
|
|
21
22
|
) -> None:
|
|
22
|
-
|
|
23
|
-
self.env = env
|
|
23
|
+
super().__init__(code_model, env)
|
|
24
24
|
self.request_builders = request_builders
|
|
25
25
|
self.group_name = request_builders[0].group_name
|
|
26
26
|
|
|
27
27
|
@property
|
|
28
28
|
def imports(self) -> FileImport:
|
|
29
|
-
file_import =
|
|
29
|
+
file_import = self.init_file_import()
|
|
30
30
|
for request_builder in self.request_builders:
|
|
31
31
|
if request_builder.group_name == self.group_name:
|
|
32
32
|
file_import.merge(request_builder.imports())
|
|
@@ -8,13 +8,14 @@ import logging
|
|
|
8
8
|
from typing import Dict, Any, Union, Tuple
|
|
9
9
|
from jinja2 import Environment
|
|
10
10
|
|
|
11
|
-
from autorest.codegen.models.credential_types import
|
|
11
|
+
from autorest.codegen.models.credential_types import KeyCredentialType
|
|
12
12
|
from autorest.codegen.models.credential_types import TokenCredentialType
|
|
13
|
-
from autorest.codegen.models.imports import
|
|
13
|
+
from autorest.codegen.models.imports import ImportType
|
|
14
14
|
from autorest.codegen.models.operation import OperationBase
|
|
15
15
|
from autorest.codegen.models.operation_group import OperationGroup
|
|
16
16
|
from autorest.codegen.models.parameter import Parameter, BodyParameter
|
|
17
17
|
from autorest.codegen.serializers.import_serializer import FileImportSerializer
|
|
18
|
+
from autorest.codegen.serializers.base_serializer import BaseSerializer
|
|
18
19
|
from ..models import CodeModel
|
|
19
20
|
from .utils import get_namespace_config, get_namespace_from_package_name
|
|
20
21
|
from ..._utils import to_snake_case
|
|
@@ -22,7 +23,7 @@ from ..._utils import to_snake_case
|
|
|
22
23
|
_LOGGER = logging.getLogger(__name__)
|
|
23
24
|
|
|
24
25
|
|
|
25
|
-
class SampleSerializer:
|
|
26
|
+
class SampleSerializer(BaseSerializer):
|
|
26
27
|
def __init__(
|
|
27
28
|
self,
|
|
28
29
|
code_model: CodeModel,
|
|
@@ -32,8 +33,7 @@ class SampleSerializer:
|
|
|
32
33
|
sample: Dict[str, Any],
|
|
33
34
|
file_name: str,
|
|
34
35
|
) -> None:
|
|
35
|
-
|
|
36
|
-
self.env = env
|
|
36
|
+
super().__init__(code_model, env)
|
|
37
37
|
self.operation_group = operation_group
|
|
38
38
|
self.operation = operation
|
|
39
39
|
self.sample = sample
|
|
@@ -43,7 +43,7 @@ class SampleSerializer:
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
def _imports(self) -> FileImportSerializer:
|
|
46
|
-
imports =
|
|
46
|
+
imports = self.init_file_import()
|
|
47
47
|
namespace_from_package_name = get_namespace_from_package_name(
|
|
48
48
|
self.code_model.options["package_name"]
|
|
49
49
|
)
|
|
@@ -63,10 +63,12 @@ class SampleSerializer:
|
|
|
63
63
|
imports.add_submodule_import(
|
|
64
64
|
"azure.identity", "DefaultAzureCredential", ImportType.THIRDPARTY
|
|
65
65
|
)
|
|
66
|
-
elif isinstance(credential_type,
|
|
66
|
+
elif isinstance(credential_type, KeyCredentialType):
|
|
67
67
|
imports.add_import("os", ImportType.STDLIB)
|
|
68
68
|
imports.add_submodule_import(
|
|
69
|
-
"
|
|
69
|
+
f"{imports.import_core}.credentials",
|
|
70
|
+
"AzureKeyCredential",
|
|
71
|
+
ImportType.THIRDPARTY,
|
|
70
72
|
)
|
|
71
73
|
for param in self.operation.parameters.positional:
|
|
72
74
|
if (
|
|
@@ -83,7 +85,7 @@ class SampleSerializer:
|
|
|
83
85
|
credential_type = getattr(self.code_model.clients[0].credential, "type", None)
|
|
84
86
|
if isinstance(credential_type, TokenCredentialType):
|
|
85
87
|
special_param.update({"credential": "DefaultAzureCredential()"})
|
|
86
|
-
elif isinstance(credential_type,
|
|
88
|
+
elif isinstance(credential_type, KeyCredentialType):
|
|
87
89
|
special_param.update(
|
|
88
90
|
{"credential": 'AzureKeyCredential(key=os.getenv("AZURE_KEY"))'}
|
|
89
91
|
)
|
|
@@ -3,19 +3,14 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from jinja2 import Environment
|
|
7
|
-
from ..models import CodeModel
|
|
8
6
|
from ..models.imports import FileImport, ImportType
|
|
9
7
|
from .import_serializer import FileImportSerializer
|
|
8
|
+
from .base_serializer import BaseSerializer
|
|
10
9
|
|
|
11
10
|
|
|
12
|
-
class TypesSerializer:
|
|
13
|
-
def __init__(self, code_model: CodeModel, env: Environment) -> None:
|
|
14
|
-
self.code_model = code_model
|
|
15
|
-
self.env = env
|
|
16
|
-
|
|
11
|
+
class TypesSerializer(BaseSerializer):
|
|
17
12
|
def imports(self) -> FileImport:
|
|
18
|
-
file_import =
|
|
13
|
+
file_import = self.init_file_import()
|
|
19
14
|
if self.code_model.named_unions:
|
|
20
15
|
file_import.add_submodule_import(
|
|
21
16
|
"typing",
|
|
@@ -51,10 +51,12 @@ class {{ client.name }}Configuration: {{ client.config.pylint_disable }}
|
|
|
51
51
|
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
|
|
52
52
|
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
|
|
53
53
|
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
|
|
54
|
+
{% if not code_model.options["unbranded"] %}
|
|
54
55
|
self.http_logging_policy = kwargs.get('http_logging_policy') or {{ "ARM" if client.code_model.options['azure_arm'] else "policies." }}HttpLoggingPolicy(**kwargs)
|
|
55
|
-
self.retry_policy = kwargs.get('retry_policy') or policies.{{ keywords.async_class }}RetryPolicy(**kwargs)
|
|
56
56
|
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
|
|
57
57
|
self.redirect_policy = kwargs.get('redirect_policy') or policies.{{ keywords.async_class }}RedirectPolicy(**kwargs)
|
|
58
|
+
{% endif %}
|
|
59
|
+
self.retry_policy = kwargs.get('retry_policy') or policies.{{ keywords.async_class }}RetryPolicy(**kwargs)
|
|
58
60
|
self.authentication_policy = kwargs.get('authentication_policy')
|
|
59
61
|
{% if client.credential and client.credential.type.policy is defined %}
|
|
60
62
|
{# only adding this if credential_scopes is not passed during code generation #}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
{{ code_model.options['license_header'] }}
|
|
3
3
|
|
|
4
4
|
from enum import Enum
|
|
5
|
-
from
|
|
5
|
+
from {{ file_import.import_core_case_insensitive_enum }} import CaseInsensitiveEnumMeta
|
|
6
6
|
|
|
7
7
|
{% for enum in code_model.enums | sort %}
|
|
8
8
|
{% include "enum.py.jinja2" %}
|
|
@@ -19,10 +19,10 @@ import email
|
|
|
19
19
|
from datetime import datetime, date, time, timedelta, timezone
|
|
20
20
|
from json import JSONEncoder
|
|
21
21
|
import isodate
|
|
22
|
-
from
|
|
23
|
-
from
|
|
24
|
-
from
|
|
25
|
-
from
|
|
22
|
+
from {{ file_import.import_core_exceptions }} import DeserializationError
|
|
23
|
+
from {{ file_import.import_core_case_insensitive_enum }} import CaseInsensitiveEnumMeta
|
|
24
|
+
from {{ file_import.import_core_pipeline }} import PipelineResponse
|
|
25
|
+
from {{ file_import.import_core_serialization }} import _Null
|
|
26
26
|
|
|
27
27
|
if sys.version_info >= (3, 9):
|
|
28
28
|
from collections.abc import MutableMapping
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
{% if not code_model.options["unbranded"] %}
|
|
1
2
|
{% if package_mode == "mgmtplane" -%}
|
|
2
3
|
# Microsoft Azure SDK for Python
|
|
3
4
|
|
|
@@ -66,7 +67,7 @@ Use the returned token credential to authenticate the client:
|
|
|
66
67
|
```python
|
|
67
68
|
>>> from {{ namespace }} import {{ client_name }}
|
|
68
69
|
>>> from azure.identity import DefaultAzureCredential
|
|
69
|
-
>>> from
|
|
70
|
+
>>> from {{ file_import.import_core_exceptions }} import HttpResponseError
|
|
70
71
|
|
|
71
72
|
>>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
|
|
72
73
|
>>> try:
|
|
@@ -103,3 +104,4 @@ additional questions or comments.
|
|
|
103
104
|
[pip]: https://pypi.org/project/pip/
|
|
104
105
|
[azure_sub]: https://azure.microsoft.com/free/
|
|
105
106
|
{% endif %}
|
|
107
|
+
{% endif %}
|
|
@@ -24,7 +24,7 @@ with open(os.path.join(package_folder_path, "_version.py"), "r") as fd:
|
|
|
24
24
|
|
|
25
25
|
if not version:
|
|
26
26
|
raise RuntimeError("Cannot find version information")
|
|
27
|
-
{% set description = "\"
|
|
27
|
+
{% set description = "\"" + company_name + " {} Client Library for Python\".format(PACKAGE_PPRINT_NAME)" %}
|
|
28
28
|
{% set author_email = "azpysdkhelp@microsoft.com" %}
|
|
29
29
|
{% set url = "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk" %}
|
|
30
30
|
{% else %}
|
|
@@ -43,11 +43,13 @@ setup(
|
|
|
43
43
|
long_description=open("README.md", "r").read(),
|
|
44
44
|
long_description_content_type="text/markdown",
|
|
45
45
|
license="MIT License",
|
|
46
|
-
author="
|
|
46
|
+
author="{{ company_name }} Corporation",
|
|
47
47
|
{% endif %}
|
|
48
48
|
author_email="{{ author_email }}",
|
|
49
|
+
{% if not unbranded %}
|
|
49
50
|
url="{{ url }}",
|
|
50
51
|
keywords="azure, azure sdk",
|
|
52
|
+
{% endif %}
|
|
51
53
|
{% if package_mode %}
|
|
52
54
|
classifiers=[
|
|
53
55
|
"Development Status :: {{ dev_status }}",
|
|
@@ -87,7 +89,9 @@ setup(
|
|
|
87
89
|
{% else %}
|
|
88
90
|
"isodate<1.0.0,>=0.6.1",
|
|
89
91
|
{% endif %}
|
|
90
|
-
{% if
|
|
92
|
+
{% if unbranded %}
|
|
93
|
+
"corehttp",
|
|
94
|
+
{% elif azure_arm %}
|
|
91
95
|
"azure-mgmt-core<2.0.0,>=1.3.2",
|
|
92
96
|
{% else %}
|
|
93
97
|
"azure-core<2.0.0,>=1.28.0",
|
|
@@ -63,8 +63,8 @@ import xml.etree.ElementTree as ET
|
|
|
63
63
|
|
|
64
64
|
import isodate # type: ignore
|
|
65
65
|
|
|
66
|
-
from
|
|
67
|
-
from
|
|
66
|
+
from {{ import_core_exceptions }} import DeserializationError, SerializationError
|
|
67
|
+
from {{ import_core_serialization }} import NULL as AzureCoreNull
|
|
68
68
|
|
|
69
69
|
_BOM = codecs.BOM_UTF8.decode(encoding="utf-8")
|
|
70
70
|
|
|
@@ -124,7 +124,7 @@ class RawDeserializer:
|
|
|
124
124
|
pass
|
|
125
125
|
|
|
126
126
|
return ET.fromstring(data_as_str) # nosec
|
|
127
|
-
except ET.ParseError:
|
|
127
|
+
except ET.ParseError as err:
|
|
128
128
|
# It might be because the server has an issue, and returned JSON with
|
|
129
129
|
# content-type XML....
|
|
130
130
|
# So let's try a JSON load, and if it's still broken
|
|
@@ -143,7 +143,7 @@ class RawDeserializer:
|
|
|
143
143
|
# The function hack is because Py2.7 messes up with exception
|
|
144
144
|
# context otherwise.
|
|
145
145
|
_LOGGER.critical("Wasn't XML not JSON, failing")
|
|
146
|
-
|
|
146
|
+
raise DeserializationError("XML is invalid") from err
|
|
147
147
|
raise DeserializationError("Cannot deserialize content-type: {}".format(content_type))
|
|
148
148
|
|
|
149
149
|
@classmethod
|
|
@@ -340,7 +340,7 @@ class Model(object):
|
|
|
340
340
|
return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None))
|
|
341
341
|
|
|
342
342
|
def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
|
|
343
|
-
"""Return the JSON that would be sent to
|
|
343
|
+
"""Return the JSON that would be sent to server from this model.
|
|
344
344
|
|
|
345
345
|
This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`.
|
|
346
346
|
|
|
@@ -670,7 +670,7 @@ class Serializer(object):
|
|
|
670
670
|
|
|
671
671
|
except (AttributeError, KeyError, TypeError) as err:
|
|
672
672
|
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
|
|
673
|
-
|
|
673
|
+
raise SerializationError(msg) from err
|
|
674
674
|
else:
|
|
675
675
|
return serialized
|
|
676
676
|
|
|
@@ -712,7 +712,7 @@ class Serializer(object):
|
|
|
712
712
|
]
|
|
713
713
|
data = deserializer._deserialize(data_type, data)
|
|
714
714
|
except DeserializationError as err:
|
|
715
|
-
|
|
715
|
+
raise SerializationError("Unable to build a model: " + str(err)) from err
|
|
716
716
|
|
|
717
717
|
return self._serialize(data, data_type, **kwargs)
|
|
718
718
|
|
|
@@ -828,7 +828,7 @@ class Serializer(object):
|
|
|
828
828
|
|
|
829
829
|
except (ValueError, TypeError) as err:
|
|
830
830
|
msg = "Unable to serialize value: {!r} as type: {!r}."
|
|
831
|
-
|
|
831
|
+
raise SerializationError(msg.format(data, data_type)) from err
|
|
832
832
|
else:
|
|
833
833
|
return self._serialize(data, **kwargs)
|
|
834
834
|
|
|
@@ -1178,10 +1178,10 @@ class Serializer(object):
|
|
|
1178
1178
|
return date + microseconds + "Z"
|
|
1179
1179
|
except (ValueError, OverflowError) as err:
|
|
1180
1180
|
msg = "Unable to serialize datetime object."
|
|
1181
|
-
|
|
1181
|
+
raise SerializationError(msg) from err
|
|
1182
1182
|
except AttributeError as err:
|
|
1183
1183
|
msg = "ISO-8601 object must be valid Datetime object."
|
|
1184
|
-
|
|
1184
|
+
raise TypeError(msg) from err
|
|
1185
1185
|
|
|
1186
1186
|
@staticmethod
|
|
1187
1187
|
def serialize_unix(attr, **kwargs):
|
|
@@ -1489,7 +1489,7 @@ class Deserializer(object):
|
|
|
1489
1489
|
d_attrs[attr] = value
|
|
1490
1490
|
except (AttributeError, TypeError, KeyError) as err:
|
|
1491
1491
|
msg = "Unable to deserialize to object: " + class_name # type: ignore
|
|
1492
|
-
|
|
1492
|
+
raise DeserializationError(msg) from err
|
|
1493
1493
|
else:
|
|
1494
1494
|
additional_properties = self._build_additional_properties(attributes, data)
|
|
1495
1495
|
return self._instantiate_model(response, d_attrs, additional_properties)
|
|
@@ -1660,7 +1660,7 @@ class Deserializer(object):
|
|
|
1660
1660
|
except (ValueError, TypeError, AttributeError) as err:
|
|
1661
1661
|
msg = "Unable to deserialize response data."
|
|
1662
1662
|
msg += " Data: {}, {}".format(data, data_type)
|
|
1663
|
-
|
|
1663
|
+
raise DeserializationError(msg) from err
|
|
1664
1664
|
else:
|
|
1665
1665
|
return self._deserialize(obj_type, data)
|
|
1666
1666
|
|
|
@@ -1816,7 +1816,6 @@ class Deserializer(object):
|
|
|
1816
1816
|
data = data.value
|
|
1817
1817
|
if isinstance(data, int):
|
|
1818
1818
|
# Workaround. We might consider remove it in the future.
|
|
1819
|
-
# https://github.com/Azure/azure-rest-api-specs/issues/141
|
|
1820
1819
|
try:
|
|
1821
1820
|
return list(enum_obj.__members__.values())[data]
|
|
1822
1821
|
except IndexError:
|
|
@@ -1873,7 +1872,7 @@ class Deserializer(object):
|
|
|
1873
1872
|
return decimal.Decimal(attr) # type: ignore
|
|
1874
1873
|
except decimal.DecimalException as err:
|
|
1875
1874
|
msg = "Invalid decimal {}".format(attr)
|
|
1876
|
-
|
|
1875
|
+
raise DeserializationError(msg) from err
|
|
1877
1876
|
|
|
1878
1877
|
@staticmethod
|
|
1879
1878
|
def deserialize_long(attr):
|
|
@@ -1901,7 +1900,7 @@ class Deserializer(object):
|
|
|
1901
1900
|
duration = isodate.parse_duration(attr)
|
|
1902
1901
|
except (ValueError, OverflowError, AttributeError) as err:
|
|
1903
1902
|
msg = "Cannot deserialize duration object."
|
|
1904
|
-
|
|
1903
|
+
raise DeserializationError(msg) from err
|
|
1905
1904
|
else:
|
|
1906
1905
|
return duration
|
|
1907
1906
|
|
|
@@ -1953,7 +1952,7 @@ class Deserializer(object):
|
|
|
1953
1952
|
date_obj = date_obj.astimezone(tz=TZ_UTC)
|
|
1954
1953
|
except ValueError as err:
|
|
1955
1954
|
msg = "Cannot deserialize to rfc datetime object."
|
|
1956
|
-
|
|
1955
|
+
raise DeserializationError(msg) from err
|
|
1957
1956
|
else:
|
|
1958
1957
|
return date_obj
|
|
1959
1958
|
|
|
@@ -1990,7 +1989,7 @@ class Deserializer(object):
|
|
|
1990
1989
|
raise OverflowError("Hit max or min date")
|
|
1991
1990
|
except (ValueError, OverflowError, AttributeError) as err:
|
|
1992
1991
|
msg = "Cannot deserialize datetime object."
|
|
1993
|
-
|
|
1992
|
+
raise DeserializationError(msg) from err
|
|
1994
1993
|
else:
|
|
1995
1994
|
return date_obj
|
|
1996
1995
|
|
|
@@ -2009,6 +2008,6 @@ class Deserializer(object):
|
|
|
2009
2008
|
date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC)
|
|
2010
2009
|
except ValueError as err:
|
|
2011
2010
|
msg = "Cannot deserialize to unix datetime object."
|
|
2012
|
-
|
|
2011
|
+
raise DeserializationError(msg) from err
|
|
2013
2012
|
else:
|
|
2014
2013
|
return date_obj
|
|
@@ -41,7 +41,7 @@ def get_body_parameter(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
41
41
|
def get_azure_key_credential(key: str) -> Dict[str, Any]:
|
|
42
42
|
retval = {
|
|
43
43
|
"type": KEY_TYPE,
|
|
44
|
-
"policy": {"type": "
|
|
44
|
+
"policy": {"type": "KeyCredentialPolicy", "key": key},
|
|
45
45
|
}
|
|
46
46
|
update_type(retval)
|
|
47
47
|
return retval
|
|
@@ -149,7 +149,10 @@ class MultiAPISerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
149
149
|
)
|
|
150
150
|
self.write_file(
|
|
151
151
|
Path("_serialization.py"),
|
|
152
|
-
codegen_env.get_template("serialization.py.jinja2").render(
|
|
152
|
+
codegen_env.get_template("serialization.py.jinja2").render(
|
|
153
|
+
import_core_exceptions="azure.core.exceptions",
|
|
154
|
+
import_core_serialization="azure.core.serialization",
|
|
155
|
+
),
|
|
153
156
|
)
|
|
154
157
|
|
|
155
158
|
|
|
@@ -160,10 +160,6 @@ def update_operation_group_class_name(
|
|
|
160
160
|
|
|
161
161
|
def update_paging_response(yaml_data: Dict[str, Any]) -> None:
|
|
162
162
|
yaml_data["discriminator"] = "paging"
|
|
163
|
-
yaml_data["pagerSync"] = yaml_data.get("pagerSync") or "azure.core.paging.ItemPaged"
|
|
164
|
-
yaml_data["pagerAsync"] = (
|
|
165
|
-
yaml_data.get("pagerAsync") or "azure.core.async_paging.AsyncItemPaged"
|
|
166
|
-
)
|
|
167
163
|
|
|
168
164
|
|
|
169
165
|
HEADERS_HIDE_IN_METHOD = (
|
|
@@ -184,7 +180,7 @@ HEADERS_CONVERT_IN_METHOD = {
|
|
|
184
180
|
"wireName": "match-condition",
|
|
185
181
|
"description": "The match condition to use upon the etag.",
|
|
186
182
|
"type": {
|
|
187
|
-
"type": "
|
|
183
|
+
"type": "sdkcore",
|
|
188
184
|
"name": "MatchConditions",
|
|
189
185
|
},
|
|
190
186
|
},
|
|
@@ -489,10 +485,6 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
489
485
|
item_type: Optional[Dict[str, Any]] = None,
|
|
490
486
|
) -> None:
|
|
491
487
|
self.update_operation(code_model, yaml_data, is_overload=is_overload)
|
|
492
|
-
if not yaml_data.get("pagerSync"):
|
|
493
|
-
yaml_data["pagerSync"] = "azure.core.paging.ItemPaged"
|
|
494
|
-
if not yaml_data.get("pagerAsync"):
|
|
495
|
-
yaml_data["pagerAsync"] = "azure.core.async_paging.AsyncItemPaged"
|
|
496
488
|
item_type = item_type or yaml_data["itemType"]["elementType"]
|
|
497
489
|
if yaml_data.get("nextOperation"):
|
|
498
490
|
yaml_data["nextOperation"]["groupName"] = self.pad_reserved_words(
|