@autorest/python 6.9.3 → 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 +35 -20
- package/autorest/codegen/__init__.py +252 -133
- package/autorest/codegen/_utils.py +2 -2
- package/autorest/codegen/models/__init__.py +7 -7
- package/autorest/codegen/models/base.py +6 -4
- package/autorest/codegen/models/client.py +34 -28
- 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 +77 -8
- package/autorest/codegen/models/list_type.py +1 -1
- package/autorest/codegen/models/lro_operation.py +5 -2
- package/autorest/codegen/models/model_type.py +1 -1
- package/autorest/codegen/models/operation.py +26 -18
- 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 +27 -28
- package/autorest/codegen/models/property.py +3 -1
- package/autorest/codegen/models/request_builder.py +11 -10
- 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 +39 -22
- 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 +22 -27
- package/autorest/codegen/serializers/model_serializer.py +8 -10
- 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 +5 -5
- 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/jsonrpc/server.py +5 -1
- package/autorest/m4reformatter/__init__.py +1 -1
- package/autorest/multiapi/models/imports.py +18 -16
- package/autorest/multiapi/serializers/__init__.py +4 -1
- package/autorest/preprocess/__init__.py +1 -9
- package/package.json +1 -1
|
@@ -4,16 +4,13 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
|
|
7
|
-
from
|
|
8
|
-
from ..models import CodeModel
|
|
7
|
+
from .base_serializer import BaseSerializer
|
|
9
8
|
|
|
10
9
|
|
|
11
|
-
class EnumSerializer:
|
|
12
|
-
def __init__(self, code_model: CodeModel, env: Environment) -> None:
|
|
13
|
-
self.code_model = code_model
|
|
14
|
-
self.env = env
|
|
15
|
-
|
|
10
|
+
class EnumSerializer(BaseSerializer):
|
|
16
11
|
def serialize(self) -> str:
|
|
17
12
|
# Generate the enum file
|
|
18
13
|
template = self.env.get_template("enum_container.py.jinja2")
|
|
19
|
-
return template.render(
|
|
14
|
+
return template.render(
|
|
15
|
+
code_model=self.code_model, file_import=self.init_file_import()
|
|
16
|
+
)
|
|
@@ -8,29 +8,20 @@ from jinja2 import Environment
|
|
|
8
8
|
from .import_serializer import FileImportSerializer, TypingSection
|
|
9
9
|
from ..models.imports import MsrestImportType
|
|
10
10
|
from ..models import (
|
|
11
|
-
FileImport,
|
|
12
11
|
ImportType,
|
|
13
12
|
CodeModel,
|
|
14
13
|
TokenCredentialType,
|
|
15
14
|
Client,
|
|
16
15
|
)
|
|
17
16
|
from .client_serializer import ClientSerializer, ConfigSerializer
|
|
17
|
+
from .base_serializer import BaseSerializer
|
|
18
18
|
|
|
19
|
-
_PACKAGE_MODE_FILES = [
|
|
20
|
-
"CHANGELOG.md.jinja2",
|
|
21
|
-
"dev_requirements.txt.jinja2",
|
|
22
|
-
"LICENSE.jinja2",
|
|
23
|
-
"MANIFEST.in.jinja2",
|
|
24
|
-
"README.md.jinja2",
|
|
25
|
-
]
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
class GeneralSerializer:
|
|
20
|
+
class GeneralSerializer(BaseSerializer):
|
|
29
21
|
"""General serializer for SDK root level files"""
|
|
30
22
|
|
|
31
23
|
def __init__(self, code_model: CodeModel, env: Environment, async_mode: bool):
|
|
32
|
-
|
|
33
|
-
self.env = env
|
|
24
|
+
super().__init__(code_model, env)
|
|
34
25
|
self.async_mode = async_mode
|
|
35
26
|
|
|
36
27
|
def serialize_setup_file(self) -> str:
|
|
@@ -68,7 +59,7 @@ class GeneralSerializer:
|
|
|
68
59
|
}
|
|
69
60
|
params.update(self.code_model.options)
|
|
70
61
|
params.update(kwargs)
|
|
71
|
-
return template.render(**params)
|
|
62
|
+
return template.render(file_import=self.init_file_import(), **params)
|
|
72
63
|
|
|
73
64
|
def serialize_pkgutil_init_file(self) -> str:
|
|
74
65
|
template = self.env.get_template("pkgutil_init.py.jinja2")
|
|
@@ -85,7 +76,7 @@ class GeneralSerializer:
|
|
|
85
76
|
def serialize_service_client_file(self, clients: List[Client]) -> str:
|
|
86
77
|
template = self.env.get_template("client_container.py.jinja2")
|
|
87
78
|
|
|
88
|
-
imports =
|
|
79
|
+
imports = self.init_file_import()
|
|
89
80
|
for client in clients:
|
|
90
81
|
imports.merge(client.imports(self.async_mode))
|
|
91
82
|
|
|
@@ -101,12 +92,12 @@ class GeneralSerializer:
|
|
|
101
92
|
template = self.env.get_template("vendor.py.jinja2")
|
|
102
93
|
|
|
103
94
|
# configure imports
|
|
104
|
-
file_import =
|
|
95
|
+
file_import = self.init_file_import()
|
|
105
96
|
if self.code_model.need_request_converter:
|
|
106
97
|
file_import.add_submodule_import(
|
|
107
98
|
"azure.core.pipeline.transport",
|
|
108
99
|
"HttpRequest",
|
|
109
|
-
ImportType.
|
|
100
|
+
ImportType.SDKCORE,
|
|
110
101
|
)
|
|
111
102
|
|
|
112
103
|
if self.code_model.need_mixin_abc:
|
|
@@ -116,16 +107,15 @@ class GeneralSerializer:
|
|
|
116
107
|
ImportType.STDLIB,
|
|
117
108
|
)
|
|
118
109
|
file_import.add_submodule_import(
|
|
119
|
-
|
|
110
|
+
file_import.import_core_pipeline_client,
|
|
120
111
|
f"{'Async' if self.async_mode else ''}PipelineClient",
|
|
121
|
-
ImportType.
|
|
112
|
+
ImportType.SDKCORE,
|
|
122
113
|
TypingSection.TYPING,
|
|
123
114
|
)
|
|
124
115
|
file_import.add_msrest_import(
|
|
125
|
-
self.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
TypingSection.TYPING,
|
|
116
|
+
relative_path=".." if self.async_mode else ".",
|
|
117
|
+
msrest_import_type=MsrestImportType.SerializerDeserializer,
|
|
118
|
+
typing_section=TypingSection.TYPING,
|
|
129
119
|
)
|
|
130
120
|
for client in clients:
|
|
131
121
|
file_import.add_submodule_import(
|
|
@@ -136,9 +126,9 @@ class GeneralSerializer:
|
|
|
136
126
|
if self.code_model.has_etag:
|
|
137
127
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
138
128
|
file_import.add_submodule_import(
|
|
139
|
-
|
|
129
|
+
file_import.import_core,
|
|
140
130
|
"MatchConditions",
|
|
141
|
-
ImportType.
|
|
131
|
+
ImportType.SDKCORE,
|
|
142
132
|
)
|
|
143
133
|
|
|
144
134
|
return template.render(
|
|
@@ -152,7 +142,7 @@ class GeneralSerializer:
|
|
|
152
142
|
|
|
153
143
|
def serialize_config_file(self, clients: List[Client]) -> str:
|
|
154
144
|
template = self.env.get_template("config_container.py.jinja2")
|
|
155
|
-
imports =
|
|
145
|
+
imports = self.init_file_import()
|
|
156
146
|
for client in self.code_model.clients:
|
|
157
147
|
imports.merge(client.config.imports(self.async_mode))
|
|
158
148
|
return template.render(
|
|
@@ -169,11 +159,16 @@ class GeneralSerializer:
|
|
|
169
159
|
|
|
170
160
|
def serialize_serialization_file(self) -> str:
|
|
171
161
|
template = self.env.get_template("serialization.py.jinja2")
|
|
172
|
-
return template.render(
|
|
162
|
+
return template.render(
|
|
163
|
+
import_core_exceptions=self.init_file_import().import_core_exceptions,
|
|
164
|
+
import_core_serialization=self.init_file_import().import_core_serialization,
|
|
165
|
+
)
|
|
173
166
|
|
|
174
167
|
def serialize_model_base_file(self) -> str:
|
|
175
168
|
template = self.env.get_template("model_base.py.jinja2")
|
|
176
|
-
return template.render(
|
|
169
|
+
return template.render(
|
|
170
|
+
code_model=self.code_model, file_import=self.init_file_import()
|
|
171
|
+
)
|
|
177
172
|
|
|
178
173
|
def serialize_validation_file(self) -> str:
|
|
179
174
|
template = self.env.get_template("validation.py.jinja2")
|
|
@@ -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,9 +129,11 @@ 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="..",
|
|
135
|
+
msrest_import_type=MsrestImportType.Module,
|
|
136
|
+
typing_section=TypingSection.REGULAR,
|
|
139
137
|
)
|
|
140
138
|
for model in self.code_model.model_types:
|
|
141
139
|
file_import.merge(model.imports(is_operation_file=False))
|
|
@@ -200,7 +198,7 @@ class MsrestModelSerializer(_ModelSerializer):
|
|
|
200
198
|
|
|
201
199
|
class DpgModelSerializer(_ModelSerializer):
|
|
202
200
|
def imports(self) -> FileImport:
|
|
203
|
-
file_import =
|
|
201
|
+
file_import = self.init_file_import()
|
|
204
202
|
file_import.add_submodule_import(
|
|
205
203
|
"..",
|
|
206
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
|
|
@@ -553,7 +553,7 @@ class Model(_MyMutableMapping):
|
|
|
553
553
|
if exclude_readonly:
|
|
554
554
|
readonly_props = [p._rest_name for p in self._attr_to_rest_field.values() if _is_readonly(p)]
|
|
555
555
|
for k, v in self.items():
|
|
556
|
-
if exclude_readonly and k in readonly_props: # pyright: reportUnboundVariable
|
|
556
|
+
if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable]
|
|
557
557
|
continue
|
|
558
558
|
result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly)
|
|
559
559
|
return result
|
|
@@ -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
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
import typing
|
|
6
7
|
import contextlib
|
|
7
8
|
import os
|
|
8
9
|
import sys
|
|
9
10
|
import logging
|
|
10
11
|
|
|
11
12
|
from jsonrpc import dispatcher, JSONRPCResponseManager
|
|
13
|
+
from jsonrpc.jsonrpc2 import JSONRPC20Response
|
|
12
14
|
|
|
13
15
|
from .stdstream import read_message, write_message
|
|
14
16
|
|
|
@@ -99,7 +101,9 @@ def main() -> None:
|
|
|
99
101
|
_LOGGER.debug("Trying to read")
|
|
100
102
|
message = read_message()
|
|
101
103
|
|
|
102
|
-
response =
|
|
104
|
+
response = typing.cast(
|
|
105
|
+
JSONRPC20Response, JSONRPCResponseManager.handle(message, dispatcher)
|
|
106
|
+
).json
|
|
103
107
|
_LOGGER.debug("Produced: %s", response)
|
|
104
108
|
write_message(response)
|
|
105
109
|
_LOGGER.debug("Message processed")
|