@autorest/python 5.15.0 → 5.18.0
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/ChangeLog.md +98 -4
- package/README.md +30 -4
- package/autorest/__init__.py +2 -3
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +122 -211
- package/autorest/codegen/models/__init__.py +122 -78
- package/autorest/codegen/models/base_builder.py +70 -72
- package/autorest/codegen/models/base_model.py +7 -5
- package/autorest/codegen/models/{base_schema.py → base_type.py} +68 -45
- package/autorest/codegen/models/client.py +193 -40
- package/autorest/codegen/models/code_model.py +145 -245
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/constant_type.py +122 -0
- package/autorest/codegen/models/credential_types.py +224 -0
- package/autorest/codegen/models/dictionary_type.py +131 -0
- package/autorest/codegen/models/enum_type.py +195 -0
- package/autorest/codegen/models/imports.py +93 -41
- package/autorest/codegen/models/list_type.py +149 -0
- package/autorest/codegen/models/lro_operation.py +90 -133
- package/autorest/codegen/models/lro_paging_operation.py +28 -12
- package/autorest/codegen/models/model_type.py +262 -0
- package/autorest/codegen/models/operation.py +412 -259
- package/autorest/codegen/models/operation_group.py +80 -91
- package/autorest/codegen/models/paging_operation.py +101 -117
- package/autorest/codegen/models/parameter.py +302 -341
- package/autorest/codegen/models/parameter_list.py +373 -357
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +136 -134
- package/autorest/codegen/models/request_builder.py +138 -86
- package/autorest/codegen/models/request_builder_parameter.py +122 -86
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +13 -17
- package/autorest/codegen/serializers/__init__.py +212 -112
- package/autorest/codegen/serializers/builder_serializer.py +931 -1040
- package/autorest/codegen/serializers/client_serializer.py +140 -84
- package/autorest/codegen/serializers/general_serializer.py +26 -50
- package/autorest/codegen/serializers/import_serializer.py +96 -31
- package/autorest/codegen/serializers/metadata_serializer.py +39 -79
- package/autorest/codegen/serializers/model_base_serializer.py +62 -34
- package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
- package/autorest/codegen/serializers/model_init_serializer.py +4 -2
- package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
- package/autorest/codegen/serializers/operation_groups_serializer.py +21 -19
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/patch_serializer.py +4 -1
- package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
- package/autorest/codegen/serializers/utils.py +0 -126
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
- package/autorest/codegen/templates/config.py.jinja2 +13 -13
- package/autorest/codegen/templates/enum.py.jinja2 +4 -4
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +3 -3
- package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
- package/autorest/codegen/templates/model.py.jinja2 +23 -24
- package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
- package/autorest/codegen/templates/operation.py.jinja2 +10 -14
- package/autorest/codegen/templates/operation_group.py.jinja2 +9 -15
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -10
- package/autorest/codegen/templates/setup.py.jinja2 +9 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +28 -9
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/m4reformatter/__init__.py +1126 -0
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +24 -17
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +20 -25
- package/autorest/multiapi/serializers/import_serializer.py +47 -17
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/postprocess/__init__.py +202 -0
- package/autorest/postprocess/get_all.py +19 -0
- package/autorest/postprocess/venvtools.py +73 -0
- package/autorest/preprocess/__init__.py +210 -0
- package/autorest/preprocess/helpers.py +54 -0
- package/autorest/{namer → preprocess}/python_mappings.py +25 -32
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/constant_schema.py +0 -101
- package/autorest/codegen/models/credential_model.py +0 -47
- package/autorest/codegen/models/credential_schema.py +0 -91
- package/autorest/codegen/models/credential_schema_policy.py +0 -77
- package/autorest/codegen/models/dictionary_schema.py +0 -103
- package/autorest/codegen/models/enum_schema.py +0 -215
- package/autorest/codegen/models/list_schema.py +0 -123
- package/autorest/codegen/models/object_schema.py +0 -253
- package/autorest/codegen/models/primitive_schemas.py +0 -466
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
- package/autorest/codegen/models/rest.py +0 -42
- package/autorest/codegen/models/schema_request.py +0 -45
- package/autorest/codegen/models/schema_response.py +0 -136
- package/autorest/codegen/serializers/rest_serializer.py +0 -57
- package/autorest/namer/__init__.py +0 -25
- package/autorest/namer/name_converter.py +0 -412
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
import datetime
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
from .base_type import BaseType
|
|
11
|
+
from .imports import FileImport, ImportType, TypingSection
|
|
12
|
+
from .utils import add_to_description
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from .code_model import CodeModel
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class RawString(object):
|
|
19
|
+
def __init__(self, string: str) -> None:
|
|
20
|
+
self.string = string
|
|
21
|
+
|
|
22
|
+
def __repr__(self) -> str:
|
|
23
|
+
return "r'{}'".format(self.string.replace("'", "\\'"))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class PrimitiveType(BaseType): # pylint: disable=abstract-method
|
|
27
|
+
def description(
|
|
28
|
+
self, *, is_operation_file: bool # pylint: disable=unused-argument
|
|
29
|
+
) -> str:
|
|
30
|
+
return ""
|
|
31
|
+
|
|
32
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
33
|
+
return self.docstring_type(**kwargs)
|
|
34
|
+
|
|
35
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
36
|
+
return self.docstring_type()
|
|
37
|
+
|
|
38
|
+
def get_json_template_representation(
|
|
39
|
+
self,
|
|
40
|
+
*,
|
|
41
|
+
optional: bool = True,
|
|
42
|
+
client_default_value_declaration: Optional[str] = None,
|
|
43
|
+
description: Optional[str] = None,
|
|
44
|
+
) -> Any:
|
|
45
|
+
comment = ""
|
|
46
|
+
if optional:
|
|
47
|
+
comment = add_to_description(comment, "Optional.")
|
|
48
|
+
if self.client_default_value is not None:
|
|
49
|
+
client_default_value_declaration = (
|
|
50
|
+
client_default_value_declaration
|
|
51
|
+
or self.get_declaration(self.client_default_value)
|
|
52
|
+
)
|
|
53
|
+
if client_default_value_declaration:
|
|
54
|
+
comment = add_to_description(
|
|
55
|
+
comment, f"Default value is {client_default_value_declaration}."
|
|
56
|
+
)
|
|
57
|
+
else:
|
|
58
|
+
client_default_value_declaration = (
|
|
59
|
+
self.default_template_representation_declaration
|
|
60
|
+
)
|
|
61
|
+
if description:
|
|
62
|
+
comment = add_to_description(comment, description)
|
|
63
|
+
if comment:
|
|
64
|
+
comment = f"# {comment}"
|
|
65
|
+
return f"{client_default_value_declaration}{comment}"
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def default_template_representation_declaration(self) -> str:
|
|
69
|
+
return self.get_declaration(self.docstring_type())
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class BooleanType(PrimitiveType):
|
|
73
|
+
@property
|
|
74
|
+
def serialization_type(self) -> str:
|
|
75
|
+
return "bool"
|
|
76
|
+
|
|
77
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
78
|
+
return "bool"
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def instance_check_template(self) -> str:
|
|
82
|
+
return "isinstance({}, bool)"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class BinaryType(PrimitiveType):
|
|
86
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
87
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
88
|
+
self.type = "IO"
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def serialization_type(self) -> str:
|
|
92
|
+
return self.type
|
|
93
|
+
|
|
94
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
95
|
+
return self.type
|
|
96
|
+
|
|
97
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
98
|
+
return self.docstring_type(**kwargs)
|
|
99
|
+
|
|
100
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
101
|
+
return "IO"
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def default_template_representation_declaration(self) -> str:
|
|
105
|
+
return self.get_declaration(b"bytes")
|
|
106
|
+
|
|
107
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
108
|
+
file_import = FileImport()
|
|
109
|
+
file_import.add_submodule_import("typing", "IO", ImportType.STDLIB)
|
|
110
|
+
return file_import
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def instance_check_template(self) -> str:
|
|
114
|
+
return "isinstance({}, (IO, bytes))"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class BinaryIteratorType(PrimitiveType):
|
|
118
|
+
"""Type returned by response if response is a streamed response"""
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def serialization_type(self) -> str:
|
|
122
|
+
return "IO"
|
|
123
|
+
|
|
124
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
125
|
+
return "AsyncIterator[bytes]" if kwargs.pop("async_mode") else "Iterator[bytes]"
|
|
126
|
+
|
|
127
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
128
|
+
return self.docstring_type(**kwargs)
|
|
129
|
+
|
|
130
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
131
|
+
iterator = "Async iterator" if kwargs.pop("async_mode") else "Iterator"
|
|
132
|
+
return f"{iterator} of the response bytes"
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def default_template_representation_declaration(self) -> str:
|
|
136
|
+
return self.get_declaration(f"Iterator[bytes]")
|
|
137
|
+
|
|
138
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
139
|
+
file_import = FileImport()
|
|
140
|
+
iterator = "AsyncIterator" if kwargs.pop("async_mode") else "Iterator"
|
|
141
|
+
file_import.add_submodule_import("typing", iterator, ImportType.STDLIB)
|
|
142
|
+
return file_import
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def instance_check_template(self) -> str:
|
|
146
|
+
return "isinstance({}, Iterator)"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class AnyType(PrimitiveType):
|
|
150
|
+
@property
|
|
151
|
+
def serialization_type(self) -> str:
|
|
152
|
+
return "object"
|
|
153
|
+
|
|
154
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
155
|
+
return "any"
|
|
156
|
+
|
|
157
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
158
|
+
return "Any"
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def default_template_representation_declaration(self) -> str:
|
|
162
|
+
return self.get_declaration({})
|
|
163
|
+
|
|
164
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
165
|
+
file_import = FileImport()
|
|
166
|
+
file_import.add_submodule_import(
|
|
167
|
+
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
168
|
+
)
|
|
169
|
+
return file_import
|
|
170
|
+
|
|
171
|
+
@property
|
|
172
|
+
def instance_check_template(self) -> str:
|
|
173
|
+
raise ValueError(
|
|
174
|
+
"Shouldn't do instance check on an anytype, it can be anything"
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class AnyObjectType(PrimitiveType):
|
|
179
|
+
@property
|
|
180
|
+
def serialization_type(self) -> str:
|
|
181
|
+
return "object"
|
|
182
|
+
|
|
183
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
184
|
+
return "JSON"
|
|
185
|
+
|
|
186
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
187
|
+
return "JSON"
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def default_template_representation_declaration(self) -> str:
|
|
191
|
+
return self.get_declaration({})
|
|
192
|
+
|
|
193
|
+
@property
|
|
194
|
+
def instance_check_template(self) -> str:
|
|
195
|
+
return "isinstance({}, MutableMapping)"
|
|
196
|
+
|
|
197
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
198
|
+
file_import = FileImport()
|
|
199
|
+
file_import.define_mutable_mapping_type()
|
|
200
|
+
file_import.add_import("sys", ImportType.STDLIB)
|
|
201
|
+
return file_import
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class NumberType(PrimitiveType): # pylint: disable=abstract-method
|
|
205
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
206
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
207
|
+
self.precision: Optional[int] = yaml_data.get("precision")
|
|
208
|
+
self.multiple: Optional[int] = yaml_data.get("multipleOf")
|
|
209
|
+
self.maximum: Optional[int] = yaml_data.get("maximum")
|
|
210
|
+
self.minimum: Optional[int] = yaml_data.get("minimum")
|
|
211
|
+
self.exclusive_maximum: Optional[int] = yaml_data.get("exclusiveMaximum")
|
|
212
|
+
self.exclusive_minimum: Optional[int] = yaml_data.get("exclusiveMinimum")
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def serialization_constraints(self) -> List[str]:
|
|
216
|
+
validation_constraints = [
|
|
217
|
+
f"maximum_ex={self.maximum}"
|
|
218
|
+
if self.maximum is not None and self.exclusive_maximum
|
|
219
|
+
else None,
|
|
220
|
+
f"maximum={self.maximum}"
|
|
221
|
+
if self.maximum is not None and not self.exclusive_maximum
|
|
222
|
+
else None,
|
|
223
|
+
f"minimum_ex={self.minimum}"
|
|
224
|
+
if self.minimum is not None and self.exclusive_minimum
|
|
225
|
+
else None,
|
|
226
|
+
f"minimum={self.minimum}"
|
|
227
|
+
if self.minimum is not None and not self.exclusive_minimum
|
|
228
|
+
else None,
|
|
229
|
+
f"multiple={self.multiple}" if self.multiple else None,
|
|
230
|
+
]
|
|
231
|
+
return [x for x in validation_constraints if x is not None]
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def validation(self) -> Optional[Dict[str, Union[bool, int, str]]]:
|
|
235
|
+
validation: Dict[str, Union[bool, int, str]] = {}
|
|
236
|
+
if self.maximum is not None:
|
|
237
|
+
if self.exclusive_maximum:
|
|
238
|
+
validation["maximum_ex"] = self.maximum
|
|
239
|
+
else:
|
|
240
|
+
validation["maximum"] = self.maximum
|
|
241
|
+
if self.minimum is not None:
|
|
242
|
+
if self.exclusive_minimum:
|
|
243
|
+
validation["minimum_ex"] = self.minimum
|
|
244
|
+
else:
|
|
245
|
+
validation["minimum"] = self.minimum
|
|
246
|
+
if self.multiple:
|
|
247
|
+
validation["multiple"] = self.multiple
|
|
248
|
+
return validation or None
|
|
249
|
+
|
|
250
|
+
@property
|
|
251
|
+
def default_template_representation_declaration(self) -> str:
|
|
252
|
+
default_value = 0 if self.docstring_type() == "int" else 0.0
|
|
253
|
+
return self.get_declaration(default_value)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class IntegerType(NumberType):
|
|
257
|
+
@property
|
|
258
|
+
def serialization_type(self) -> str:
|
|
259
|
+
return "int"
|
|
260
|
+
|
|
261
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
262
|
+
return "int"
|
|
263
|
+
|
|
264
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
265
|
+
return "int"
|
|
266
|
+
|
|
267
|
+
@property
|
|
268
|
+
def default_template_representation_declaration(self) -> str:
|
|
269
|
+
return self.get_declaration(0)
|
|
270
|
+
|
|
271
|
+
@property
|
|
272
|
+
def instance_check_template(self) -> str:
|
|
273
|
+
return "isinstance({}, int)"
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
class FloatType(NumberType):
|
|
277
|
+
@property
|
|
278
|
+
def serialization_type(self) -> str:
|
|
279
|
+
return "float"
|
|
280
|
+
|
|
281
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
282
|
+
return "float"
|
|
283
|
+
|
|
284
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
285
|
+
return "float"
|
|
286
|
+
|
|
287
|
+
@property
|
|
288
|
+
def default_template_representation_declaration(self) -> str:
|
|
289
|
+
return self.get_declaration(0.0)
|
|
290
|
+
|
|
291
|
+
@property
|
|
292
|
+
def instance_check_template(self) -> str:
|
|
293
|
+
return "isinstance({}, float)"
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
class StringType(PrimitiveType):
|
|
297
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
298
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
299
|
+
self.max_length: Optional[int] = yaml_data.get("maxLength")
|
|
300
|
+
self.min_length: Optional[int] = (
|
|
301
|
+
yaml_data.get("minLength", 0)
|
|
302
|
+
if yaml_data.get("maxLength")
|
|
303
|
+
else yaml_data.get("minLength")
|
|
304
|
+
)
|
|
305
|
+
self.pattern: Optional[str] = yaml_data.get("pattern")
|
|
306
|
+
|
|
307
|
+
@property
|
|
308
|
+
def serialization_constraints(self) -> List[str]:
|
|
309
|
+
validation_constraints = [
|
|
310
|
+
f"max_length={self.max_length}" if self.max_length is not None else None,
|
|
311
|
+
f"min_length={self.min_length}" if self.min_length is not None else None,
|
|
312
|
+
f"pattern={RawString(self.pattern)}" if self.pattern else None,
|
|
313
|
+
]
|
|
314
|
+
return [x for x in validation_constraints if x is not None]
|
|
315
|
+
|
|
316
|
+
@property
|
|
317
|
+
def validation(self) -> Optional[Dict[str, Union[bool, int, str]]]:
|
|
318
|
+
validation: Dict[str, Union[bool, int, str]] = {}
|
|
319
|
+
if self.max_length is not None:
|
|
320
|
+
validation["max_length"] = self.max_length
|
|
321
|
+
if self.min_length is not None:
|
|
322
|
+
validation["min_length"] = self.min_length
|
|
323
|
+
if self.pattern:
|
|
324
|
+
# https://github.com/Azure/autorest.python/issues/407
|
|
325
|
+
validation["pattern"] = RawString(self.pattern) # type: ignore
|
|
326
|
+
return validation or None
|
|
327
|
+
|
|
328
|
+
def get_declaration(self, value) -> str:
|
|
329
|
+
return f'"{value}"'
|
|
330
|
+
|
|
331
|
+
@property
|
|
332
|
+
def serialization_type(self) -> str:
|
|
333
|
+
return "str"
|
|
334
|
+
|
|
335
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
336
|
+
return "str"
|
|
337
|
+
|
|
338
|
+
@property
|
|
339
|
+
def instance_check_template(self) -> str:
|
|
340
|
+
return "isinstance({}, str)"
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
class DatetimeType(PrimitiveType):
|
|
344
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
345
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
346
|
+
self.format = self.Formats(yaml_data["format"])
|
|
347
|
+
|
|
348
|
+
class Formats(str, Enum):
|
|
349
|
+
datetime = "date-time"
|
|
350
|
+
rfc1123 = "date-time-rfc1123"
|
|
351
|
+
|
|
352
|
+
@property
|
|
353
|
+
def serialization_type(self) -> str:
|
|
354
|
+
formats_to_attribute_type = {
|
|
355
|
+
self.Formats.datetime: "iso-8601",
|
|
356
|
+
self.Formats.rfc1123: "rfc-1123",
|
|
357
|
+
}
|
|
358
|
+
return formats_to_attribute_type[self.format]
|
|
359
|
+
|
|
360
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
361
|
+
return "~" + self.type_annotation()
|
|
362
|
+
|
|
363
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
364
|
+
return "datetime.datetime"
|
|
365
|
+
|
|
366
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
367
|
+
return "datetime"
|
|
368
|
+
|
|
369
|
+
def get_declaration(self, value: datetime.datetime) -> str:
|
|
370
|
+
"""Could be discussed, since technically I should return a datetime object,
|
|
371
|
+
but msrest will do fine.
|
|
372
|
+
"""
|
|
373
|
+
return f'"{value}"'
|
|
374
|
+
|
|
375
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
376
|
+
file_import = FileImport()
|
|
377
|
+
file_import.add_import("datetime", ImportType.STDLIB)
|
|
378
|
+
return file_import
|
|
379
|
+
|
|
380
|
+
@property
|
|
381
|
+
def default_template_representation_declaration(self):
|
|
382
|
+
return self.get_declaration(datetime.datetime(2020, 2, 20))
|
|
383
|
+
|
|
384
|
+
@property
|
|
385
|
+
def instance_check_template(self) -> str:
|
|
386
|
+
return "isinstance({}, datetime.datetime)"
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
class TimeType(PrimitiveType):
|
|
390
|
+
@property
|
|
391
|
+
def serialization_type(self) -> str:
|
|
392
|
+
return "time"
|
|
393
|
+
|
|
394
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
395
|
+
return "~" + self.type_annotation()
|
|
396
|
+
|
|
397
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
398
|
+
return "datetime.time"
|
|
399
|
+
|
|
400
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
401
|
+
return "time"
|
|
402
|
+
|
|
403
|
+
def get_declaration(self, value: datetime.time) -> str:
|
|
404
|
+
"""Could be discussed, since technically I should return a time object,
|
|
405
|
+
but msrest will do fine.
|
|
406
|
+
"""
|
|
407
|
+
return f'"{value}"'
|
|
408
|
+
|
|
409
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
410
|
+
file_import = FileImport()
|
|
411
|
+
file_import.add_import("datetime", ImportType.STDLIB)
|
|
412
|
+
return file_import
|
|
413
|
+
|
|
414
|
+
@property
|
|
415
|
+
def default_template_representation_declaration(self) -> str:
|
|
416
|
+
return self.get_declaration(datetime.time(12, 30, 0))
|
|
417
|
+
|
|
418
|
+
@property
|
|
419
|
+
def instance_check_template(self) -> str:
|
|
420
|
+
return "isinstance({}, datetime.time)"
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
class UnixTimeType(PrimitiveType):
|
|
424
|
+
@property
|
|
425
|
+
def serialization_type(self) -> str:
|
|
426
|
+
return "unix-time"
|
|
427
|
+
|
|
428
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
429
|
+
return "~" + self.type_annotation()
|
|
430
|
+
|
|
431
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
432
|
+
return "datetime.datetime"
|
|
433
|
+
|
|
434
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
435
|
+
return "datetime"
|
|
436
|
+
|
|
437
|
+
def get_declaration(self, value: datetime.datetime) -> str:
|
|
438
|
+
"""Could be discussed, since technically I should return a datetime object,
|
|
439
|
+
but msrest will do fine.
|
|
440
|
+
"""
|
|
441
|
+
return f'"{value}"'
|
|
442
|
+
|
|
443
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
444
|
+
file_import = FileImport()
|
|
445
|
+
file_import.add_import("datetime", ImportType.STDLIB)
|
|
446
|
+
return file_import
|
|
447
|
+
|
|
448
|
+
@property
|
|
449
|
+
def default_template_representation_declaration(self) -> str:
|
|
450
|
+
return self.get_declaration(datetime.datetime(2020, 2, 20))
|
|
451
|
+
|
|
452
|
+
@property
|
|
453
|
+
def instance_check_template(self) -> str:
|
|
454
|
+
return "isinstance({}, datetime.time)"
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
class DateType(PrimitiveType):
|
|
458
|
+
@property
|
|
459
|
+
def serialization_type(self) -> str:
|
|
460
|
+
return "date"
|
|
461
|
+
|
|
462
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
463
|
+
return "~" + self.type_annotation()
|
|
464
|
+
|
|
465
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
466
|
+
return "datetime.date"
|
|
467
|
+
|
|
468
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
469
|
+
return "date"
|
|
470
|
+
|
|
471
|
+
def get_declaration(self, value: datetime.date) -> str:
|
|
472
|
+
"""Could be discussed, since technically I should return a datetime object,
|
|
473
|
+
but msrest will do fine.
|
|
474
|
+
"""
|
|
475
|
+
return f'"{value}"'
|
|
476
|
+
|
|
477
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
478
|
+
file_import = FileImport()
|
|
479
|
+
file_import.add_import("datetime", ImportType.STDLIB)
|
|
480
|
+
return file_import
|
|
481
|
+
|
|
482
|
+
@property
|
|
483
|
+
def default_template_representation_declaration(self) -> str:
|
|
484
|
+
return self.get_declaration(datetime.date(2020, 2, 20))
|
|
485
|
+
|
|
486
|
+
@property
|
|
487
|
+
def instance_check_template(self) -> str:
|
|
488
|
+
return "isinstance({}, datetime.date)"
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
class DurationType(PrimitiveType):
|
|
492
|
+
@property
|
|
493
|
+
def serialization_type(self) -> str:
|
|
494
|
+
return "duration"
|
|
495
|
+
|
|
496
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
497
|
+
return "~" + self.type_annotation()
|
|
498
|
+
|
|
499
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
500
|
+
return "datetime.timedelta"
|
|
501
|
+
|
|
502
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
503
|
+
return "timedelta"
|
|
504
|
+
|
|
505
|
+
def get_declaration(self, value: datetime.timedelta) -> str:
|
|
506
|
+
"""Could be discussed, since technically I should return a datetime object,
|
|
507
|
+
but msrest will do fine.
|
|
508
|
+
"""
|
|
509
|
+
return f'"{value}"'
|
|
510
|
+
|
|
511
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
512
|
+
file_import = FileImport()
|
|
513
|
+
file_import.add_import("datetime", ImportType.STDLIB)
|
|
514
|
+
return file_import
|
|
515
|
+
|
|
516
|
+
@property
|
|
517
|
+
def default_template_representation_declaration(self) -> str:
|
|
518
|
+
return self.get_declaration(datetime.timedelta(1))
|
|
519
|
+
|
|
520
|
+
@property
|
|
521
|
+
def instance_check_template(self) -> str:
|
|
522
|
+
return "isinstance({}, datetime.timedelta)"
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
class ByteArraySchema(PrimitiveType):
|
|
526
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
527
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
528
|
+
self.format = yaml_data["format"]
|
|
529
|
+
|
|
530
|
+
@property
|
|
531
|
+
def serialization_type(self) -> str:
|
|
532
|
+
if self.format == "base64url":
|
|
533
|
+
return "base64"
|
|
534
|
+
return "bytearray"
|
|
535
|
+
|
|
536
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
537
|
+
return "bytes"
|
|
538
|
+
|
|
539
|
+
def get_declaration(self, value: str) -> str:
|
|
540
|
+
return f'bytes("{value}", encoding="utf-8")'
|
|
541
|
+
|
|
542
|
+
@property
|
|
543
|
+
def instance_check_template(self) -> str:
|
|
544
|
+
return "isinstance({}, bytes)"
|