@autorest/python 6.9.4 → 6.9.6
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 +21 -6
- 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/client.py.jinja2 +1 -1
- 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 +8 -4
- 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 +28 -34
- package/package.json +1 -1
|
@@ -195,18 +195,19 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
195
195
|
raise KeyError(f"No operation with id {operation_id} found.") from exc
|
|
196
196
|
|
|
197
197
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
198
|
-
file_import =
|
|
199
|
-
|
|
198
|
+
file_import = self.init_file_import()
|
|
200
199
|
file_import.add_submodule_import(
|
|
201
200
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
202
201
|
)
|
|
203
202
|
if self.code_model.options["azure_arm"]:
|
|
204
203
|
file_import.add_submodule_import(
|
|
205
|
-
"azure.mgmt.core", self.pipeline_class(async_mode), ImportType.
|
|
204
|
+
"azure.mgmt.core", self.pipeline_class(async_mode), ImportType.SDKCORE
|
|
206
205
|
)
|
|
207
206
|
else:
|
|
208
207
|
file_import.add_submodule_import(
|
|
209
|
-
|
|
208
|
+
file_import.import_core_pipeline_client,
|
|
209
|
+
self.pipeline_class(async_mode),
|
|
210
|
+
ImportType.SDKCORE,
|
|
210
211
|
)
|
|
211
212
|
|
|
212
213
|
for gp in self.parameters:
|
|
@@ -230,14 +231,14 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
230
231
|
typing_section=TypingSection.REGULAR,
|
|
231
232
|
)
|
|
232
233
|
file_import.add_submodule_import(
|
|
233
|
-
|
|
234
|
+
file_import.import_core_policies, "policies", ImportType.SDKCORE
|
|
234
235
|
)
|
|
235
236
|
if self.code_model.options["azure_arm"]:
|
|
236
237
|
async_prefix = "Async" if async_mode else ""
|
|
237
238
|
file_import.add_submodule_import(
|
|
238
239
|
"azure.mgmt.core.policies",
|
|
239
240
|
f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy",
|
|
240
|
-
ImportType.
|
|
241
|
+
ImportType.SDKCORE,
|
|
241
242
|
)
|
|
242
243
|
return file_import
|
|
243
244
|
|
|
@@ -247,13 +248,19 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
247
248
|
return any(o for o in self.operation_groups if o.is_mixin)
|
|
248
249
|
|
|
249
250
|
@property
|
|
250
|
-
def
|
|
251
|
-
"""
|
|
252
|
-
return
|
|
253
|
-
operation
|
|
251
|
+
def lro_operations(self) -> List["OperationType"]:
|
|
252
|
+
"""all LRO operations in this SDK?"""
|
|
253
|
+
return [
|
|
254
|
+
operation
|
|
254
255
|
for operation_group in self.operation_groups
|
|
255
256
|
for operation in operation_group.operations
|
|
256
|
-
|
|
257
|
+
if operation.operation_type in ("lro", "lropaging")
|
|
258
|
+
]
|
|
259
|
+
|
|
260
|
+
@property
|
|
261
|
+
def has_public_lro_operations(self) -> bool:
|
|
262
|
+
"""Are there any public LRO operations in this SDK?"""
|
|
263
|
+
return any(not operation.internal for operation in self.lro_operations)
|
|
257
264
|
|
|
258
265
|
@property
|
|
259
266
|
def has_operations(self) -> bool:
|
|
@@ -293,22 +300,22 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
293
300
|
if async_mode:
|
|
294
301
|
file_import.add_submodule_import("typing", "Awaitable", ImportType.STDLIB)
|
|
295
302
|
file_import.add_submodule_import(
|
|
296
|
-
|
|
303
|
+
file_import.import_core_rest,
|
|
297
304
|
"AsyncHttpResponse",
|
|
298
|
-
ImportType.
|
|
305
|
+
ImportType.SDKCORE,
|
|
299
306
|
TypingSection.CONDITIONAL,
|
|
300
307
|
)
|
|
301
308
|
else:
|
|
302
309
|
file_import.add_submodule_import(
|
|
303
|
-
|
|
310
|
+
file_import.import_core_rest,
|
|
304
311
|
"HttpResponse",
|
|
305
|
-
ImportType.
|
|
312
|
+
ImportType.SDKCORE,
|
|
306
313
|
TypingSection.CONDITIONAL,
|
|
307
314
|
)
|
|
308
315
|
file_import.add_submodule_import(
|
|
309
|
-
|
|
316
|
+
file_import.import_core_rest,
|
|
310
317
|
"HttpRequest",
|
|
311
|
-
ImportType.
|
|
318
|
+
ImportType.SDKCORE,
|
|
312
319
|
TypingSection.CONDITIONAL,
|
|
313
320
|
)
|
|
314
321
|
for og in self.operation_groups:
|
|
@@ -348,15 +355,15 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
348
355
|
except StopIteration:
|
|
349
356
|
pass
|
|
350
357
|
file_import.add_submodule_import(
|
|
351
|
-
"azure.profiles", "KnownProfiles", import_type=ImportType.
|
|
358
|
+
"azure.profiles", "KnownProfiles", import_type=ImportType.SDKCORE
|
|
352
359
|
)
|
|
353
360
|
file_import.add_submodule_import(
|
|
354
|
-
"azure.profiles", "ProfileDefinition", import_type=ImportType.
|
|
361
|
+
"azure.profiles", "ProfileDefinition", import_type=ImportType.SDKCORE
|
|
355
362
|
)
|
|
356
363
|
file_import.add_submodule_import(
|
|
357
364
|
"azure.profiles.multiapiclient",
|
|
358
365
|
"MultiApiClientMixin",
|
|
359
|
-
import_type=ImportType.
|
|
366
|
+
import_type=ImportType.SDKCORE,
|
|
360
367
|
)
|
|
361
368
|
return file_import
|
|
362
369
|
|
|
@@ -405,9 +412,9 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
405
412
|
return f"{super().name}Configuration"
|
|
406
413
|
|
|
407
414
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
408
|
-
file_import =
|
|
415
|
+
file_import = self.init_file_import()
|
|
409
416
|
file_import.add_submodule_import(
|
|
410
|
-
|
|
417
|
+
file_import.import_core_policies, "policies", ImportType.SDKCORE
|
|
411
418
|
)
|
|
412
419
|
file_import.add_submodule_import(
|
|
413
420
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
@@ -423,10 +430,10 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
423
430
|
else "ARMChallengeAuthenticationPolicy"
|
|
424
431
|
)
|
|
425
432
|
file_import.add_submodule_import(
|
|
426
|
-
"azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.
|
|
433
|
+
"azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.SDKCORE
|
|
427
434
|
)
|
|
428
435
|
file_import.add_submodule_import(
|
|
429
|
-
"azure.mgmt.core.policies", policy, ImportType.
|
|
436
|
+
"azure.mgmt.core.policies", policy, ImportType.SDKCORE
|
|
430
437
|
)
|
|
431
438
|
|
|
432
439
|
return file_import
|
|
@@ -103,7 +103,7 @@ class CombinedType(BaseType):
|
|
|
103
103
|
raise ValueError("You shouldn't do instance checks on a multiple type")
|
|
104
104
|
|
|
105
105
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
106
|
-
file_import =
|
|
106
|
+
file_import = self.init_file_import()
|
|
107
107
|
if self.name and not kwargs.get("is_types_file"):
|
|
108
108
|
file_import.add_submodule_import(
|
|
109
109
|
kwargs.pop("relative_path"),
|
|
@@ -124,7 +124,7 @@ class ConstantType(BaseType):
|
|
|
124
124
|
)
|
|
125
125
|
|
|
126
126
|
def _imports_shared(self, **kwargs: Any):
|
|
127
|
-
file_import =
|
|
127
|
+
file_import = self.init_file_import()
|
|
128
128
|
file_import.merge(self.value_type.imports(**kwargs))
|
|
129
129
|
return file_import
|
|
130
130
|
|
|
@@ -26,7 +26,7 @@ if TYPE_CHECKING:
|
|
|
26
26
|
class _CredentialPolicyBaseType:
|
|
27
27
|
"""Base class for our different credential policy types.
|
|
28
28
|
|
|
29
|
-
Inherited by our BearerTokenCredentialPolicy and
|
|
29
|
+
Inherited by our BearerTokenCredentialPolicy and KeyCredentialPolicy types.
|
|
30
30
|
"""
|
|
31
31
|
|
|
32
32
|
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
@@ -71,7 +71,7 @@ class ARMChallengeAuthenticationPolicyType(BearerTokenCredentialPolicyType):
|
|
|
71
71
|
return f"{policy_name}(self.credential, *self.credential_scopes, **kwargs)"
|
|
72
72
|
|
|
73
73
|
|
|
74
|
-
class
|
|
74
|
+
class KeyCredentialPolicyType(_CredentialPolicyBaseType):
|
|
75
75
|
def __init__(
|
|
76
76
|
self,
|
|
77
77
|
yaml_data: Dict[str, Any],
|
|
@@ -83,16 +83,26 @@ class AzureKeyCredentialPolicyType(_CredentialPolicyBaseType):
|
|
|
83
83
|
self.key = key
|
|
84
84
|
self.scheme = scheme
|
|
85
85
|
|
|
86
|
+
@property
|
|
87
|
+
def credential_name(self) -> str:
|
|
88
|
+
return (
|
|
89
|
+
"AzureKeyCredential"
|
|
90
|
+
if not self.code_model.options["unbranded"]
|
|
91
|
+
else "ServiceKeyCredential"
|
|
92
|
+
)
|
|
93
|
+
|
|
86
94
|
def call(self, async_mode: bool) -> str:
|
|
87
95
|
params = f'"{self.key}", '
|
|
88
96
|
if self.scheme:
|
|
89
97
|
params += f'prefix="{self.scheme}", '
|
|
90
|
-
return
|
|
98
|
+
return (
|
|
99
|
+
f"policies.{self.credential_name}Policy(self.credential, {params}**kwargs)"
|
|
100
|
+
)
|
|
91
101
|
|
|
92
102
|
@classmethod
|
|
93
103
|
def from_yaml(
|
|
94
104
|
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
95
|
-
) -> "
|
|
105
|
+
) -> "KeyCredentialPolicyType":
|
|
96
106
|
return cls(
|
|
97
107
|
yaml_data, code_model, yaml_data["key"], yaml_data.get("scheme", None)
|
|
98
108
|
)
|
|
@@ -103,7 +113,7 @@ CredentialPolicyType = TypeVar(
|
|
|
103
113
|
bound=Union[
|
|
104
114
|
BearerTokenCredentialPolicyType,
|
|
105
115
|
ARMChallengeAuthenticationPolicyType,
|
|
106
|
-
|
|
116
|
+
KeyCredentialPolicyType,
|
|
107
117
|
],
|
|
108
118
|
)
|
|
109
119
|
|
|
@@ -111,7 +121,7 @@ CredentialPolicyType = TypeVar(
|
|
|
111
121
|
class CredentialType(
|
|
112
122
|
Generic[CredentialPolicyType], BaseType
|
|
113
123
|
): # pylint:disable=abstract-method
|
|
114
|
-
"""Store info about the type of the credential. Can be either an
|
|
124
|
+
"""Store info about the type of the credential. Can be either an KeyCredential or a TokenCredential"""
|
|
115
125
|
|
|
116
126
|
def __init__(
|
|
117
127
|
self,
|
|
@@ -178,23 +188,23 @@ class TokenCredentialType(
|
|
|
178
188
|
|
|
179
189
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
180
190
|
if kwargs.get("async_mode"):
|
|
181
|
-
return "~
|
|
182
|
-
return "~
|
|
191
|
+
return f"~{self.init_file_import().import_core_credentials_async}.AsyncTokenCredential"
|
|
192
|
+
return f"~{self.init_file_import().import_core_credentials}.TokenCredential"
|
|
183
193
|
|
|
184
194
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
185
|
-
file_import =
|
|
195
|
+
file_import = self.init_file_import()
|
|
186
196
|
if kwargs.get("async_mode"):
|
|
187
197
|
file_import.add_submodule_import(
|
|
188
|
-
|
|
198
|
+
file_import.import_core_credentials_async,
|
|
189
199
|
"AsyncTokenCredential",
|
|
190
|
-
ImportType.
|
|
200
|
+
ImportType.SDKCORE,
|
|
191
201
|
typing_section=TypingSection.TYPING,
|
|
192
202
|
)
|
|
193
203
|
else:
|
|
194
204
|
file_import.add_submodule_import(
|
|
195
|
-
|
|
205
|
+
file_import.import_core_credentials,
|
|
196
206
|
"TokenCredential",
|
|
197
|
-
ImportType.
|
|
207
|
+
ImportType.SDKCORE,
|
|
198
208
|
typing_section=TypingSection.TYPING,
|
|
199
209
|
)
|
|
200
210
|
return file_import
|
|
@@ -204,28 +214,28 @@ class TokenCredentialType(
|
|
|
204
214
|
return "hasattr({}, 'get_token')"
|
|
205
215
|
|
|
206
216
|
|
|
207
|
-
class
|
|
217
|
+
class KeyCredentialType(
|
|
208
218
|
# pylint: disable=unsubscriptable-object
|
|
209
|
-
CredentialType[
|
|
219
|
+
CredentialType[KeyCredentialPolicyType]
|
|
210
220
|
):
|
|
211
|
-
"""Type for an
|
|
221
|
+
"""Type for an KeyCredential"""
|
|
212
222
|
|
|
213
223
|
def docstring_type(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
|
|
214
|
-
return "~
|
|
224
|
+
return f"~{self.init_file_import().import_core}.credentials.{self.policy.credential_name}"
|
|
215
225
|
|
|
216
226
|
def type_annotation(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
|
|
217
|
-
return
|
|
227
|
+
return self.policy.credential_name
|
|
218
228
|
|
|
219
229
|
@property
|
|
220
230
|
def instance_check_template(self) -> str:
|
|
221
|
-
return "isinstance({},
|
|
231
|
+
return "isinstance({}, " + f"{self.policy.credential_name})"
|
|
222
232
|
|
|
223
233
|
def imports(self, **kwargs: Any) -> FileImport: # pylint: disable=unused-argument
|
|
224
|
-
file_import =
|
|
234
|
+
file_import = self.init_file_import()
|
|
225
235
|
file_import.add_submodule_import(
|
|
226
|
-
"
|
|
227
|
-
|
|
228
|
-
ImportType.
|
|
236
|
+
f"{file_import.import_core}.credentials",
|
|
237
|
+
self.policy.credential_name,
|
|
238
|
+
ImportType.SDKCORE,
|
|
229
239
|
typing_section=TypingSection.CONDITIONAL,
|
|
230
240
|
)
|
|
231
241
|
return file_import
|
|
@@ -123,7 +123,7 @@ class DictionaryType(BaseType):
|
|
|
123
123
|
)
|
|
124
124
|
|
|
125
125
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
126
|
-
file_import =
|
|
126
|
+
file_import = self.init_file_import()
|
|
127
127
|
file_import.add_submodule_import(
|
|
128
128
|
"typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
129
129
|
)
|
|
@@ -76,7 +76,7 @@ class EnumValue(BaseType):
|
|
|
76
76
|
return self.value_type.instance_check_template
|
|
77
77
|
|
|
78
78
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
79
|
-
file_import =
|
|
79
|
+
file_import = self.init_file_import()
|
|
80
80
|
file_import.merge(self.value_type.imports(**kwargs))
|
|
81
81
|
file_import.add_literal_import()
|
|
82
82
|
file_import.add_submodule_import(
|
|
@@ -230,7 +230,7 @@ class EnumType(BaseType):
|
|
|
230
230
|
|
|
231
231
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
232
232
|
operation = kwargs.pop("operation", False)
|
|
233
|
-
file_import =
|
|
233
|
+
file_import = self.init_file_import()
|
|
234
234
|
if self.code_model.options["models_mode"]:
|
|
235
235
|
file_import.add_submodule_import(
|
|
236
236
|
"typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
|
|
|
13
13
|
class ImportType(str, Enum):
|
|
14
14
|
STDLIB = "stdlib"
|
|
15
15
|
THIRDPARTY = "thirdparty"
|
|
16
|
-
|
|
16
|
+
SDKCORE = "sdkcore"
|
|
17
17
|
LOCAL = "local"
|
|
18
18
|
BYVERSION = "by_version"
|
|
19
19
|
|
|
@@ -87,7 +87,7 @@ class TypeDefinition:
|
|
|
87
87
|
self.async_definition = async_definition
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
class FileImport:
|
|
90
|
+
class FileImport: # pylint: disable=too-many-public-methods
|
|
91
91
|
def __init__(self, code_model: "CodeModel") -> None:
|
|
92
92
|
self.imports: List[ImportModel] = []
|
|
93
93
|
self.code_model = code_model
|
|
@@ -281,7 +281,7 @@ class FileImport:
|
|
|
281
281
|
if self.code_model.options["client_side_validation"]:
|
|
282
282
|
if msrest_import_type == MsrestImportType.Module:
|
|
283
283
|
self.add_import(
|
|
284
|
-
"msrest.serialization", ImportType.
|
|
284
|
+
"msrest.serialization", ImportType.SDKCORE, typing_section
|
|
285
285
|
)
|
|
286
286
|
else:
|
|
287
287
|
self.add_submodule_import(
|
|
@@ -312,3 +312,71 @@ class FileImport:
|
|
|
312
312
|
ImportType.LOCAL,
|
|
313
313
|
typing_section,
|
|
314
314
|
)
|
|
315
|
+
|
|
316
|
+
@property
|
|
317
|
+
def import_core(self) -> str:
|
|
318
|
+
return "azure.core" if not self.code_model.options["unbranded"] else "corehttp"
|
|
319
|
+
|
|
320
|
+
@property
|
|
321
|
+
def import_core_exceptions(self) -> str:
|
|
322
|
+
return f"{self.import_core}.exceptions"
|
|
323
|
+
|
|
324
|
+
@property
|
|
325
|
+
def import_core_rest(self) -> str:
|
|
326
|
+
return f"{self.import_core}.rest"
|
|
327
|
+
|
|
328
|
+
@property
|
|
329
|
+
def import_core_credentials(self) -> str:
|
|
330
|
+
return f"{self.import_core}.credentials"
|
|
331
|
+
|
|
332
|
+
@property
|
|
333
|
+
def import_core_credentials_async(self) -> str:
|
|
334
|
+
return self.import_core + (
|
|
335
|
+
".credentials_async"
|
|
336
|
+
if not self.code_model.options["unbranded"]
|
|
337
|
+
else ".credentials"
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
@property
|
|
341
|
+
def import_core_paging(self) -> str:
|
|
342
|
+
return f"{self.import_core}.paging"
|
|
343
|
+
|
|
344
|
+
@property
|
|
345
|
+
def import_core_paging_async(self) -> str:
|
|
346
|
+
return self.import_core + (
|
|
347
|
+
".async_paging" if not self.code_model.options["unbranded"] else ".paging"
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
@property
|
|
351
|
+
def import_core_utils(self) -> str:
|
|
352
|
+
return f"{self.import_core}.utils"
|
|
353
|
+
|
|
354
|
+
@property
|
|
355
|
+
def import_core_case_insensitive_enum(self) -> str:
|
|
356
|
+
return self.import_core + (
|
|
357
|
+
"" if not self.code_model.options["unbranded"] else ".utils"
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
@property
|
|
361
|
+
def import_core_pipeline(self) -> str:
|
|
362
|
+
return self.import_core + (
|
|
363
|
+
".pipeline"
|
|
364
|
+
if not self.code_model.options["unbranded"]
|
|
365
|
+
else ".runtime.pipeline"
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
@property
|
|
369
|
+
def import_core_policies(self) -> str:
|
|
370
|
+
return self.import_core + (
|
|
371
|
+
".pipeline" if not self.code_model.options["unbranded"] else ".runtime"
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
@property
|
|
375
|
+
def import_core_serialization(self) -> str:
|
|
376
|
+
return f"{self.import_core}.serialization"
|
|
377
|
+
|
|
378
|
+
@property
|
|
379
|
+
def import_core_pipeline_client(self) -> str:
|
|
380
|
+
return self.import_core + (
|
|
381
|
+
"" if not self.code_model.options["unbranded"] else ".runtime"
|
|
382
|
+
)
|
|
@@ -146,7 +146,7 @@ class ListType(BaseType):
|
|
|
146
146
|
)
|
|
147
147
|
|
|
148
148
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
149
|
-
file_import =
|
|
149
|
+
file_import = self.init_file_import()
|
|
150
150
|
if not (
|
|
151
151
|
self.code_model.options["version_tolerant"]
|
|
152
152
|
and self.element_type.is_xml
|
|
@@ -126,11 +126,11 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
126
126
|
file_import = super().imports(async_mode, **kwargs)
|
|
127
127
|
if self.abstract:
|
|
128
128
|
return file_import
|
|
129
|
-
if async_mode:
|
|
129
|
+
if async_mode and self.code_model.options["tracing"] and self.want_tracing:
|
|
130
130
|
file_import.add_submodule_import(
|
|
131
131
|
"azure.core.tracing.decorator_async",
|
|
132
132
|
"distributed_trace_async",
|
|
133
|
-
ImportType.
|
|
133
|
+
ImportType.SDKCORE,
|
|
134
134
|
)
|
|
135
135
|
if (
|
|
136
136
|
self.code_model.options["models_mode"] == "dpg"
|
|
@@ -268,7 +268,7 @@ class JSONModelType(ModelType):
|
|
|
268
268
|
return "isinstance({}, MutableMapping)"
|
|
269
269
|
|
|
270
270
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
271
|
-
file_import =
|
|
271
|
+
file_import = self.init_file_import()
|
|
272
272
|
file_import.add_submodule_import(
|
|
273
273
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
274
274
|
)
|
|
@@ -230,7 +230,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
230
230
|
def _imports_shared(
|
|
231
231
|
self, async_mode: bool, **kwargs: Any # pylint: disable=unused-argument
|
|
232
232
|
) -> FileImport:
|
|
233
|
-
file_import =
|
|
233
|
+
file_import = self.init_file_import()
|
|
234
234
|
file_import.add_submodule_import(
|
|
235
235
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
236
236
|
)
|
|
@@ -308,7 +308,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
308
308
|
async_mode: bool,
|
|
309
309
|
) -> FileImport:
|
|
310
310
|
"""Helper method to get a request builder import."""
|
|
311
|
-
file_import =
|
|
311
|
+
file_import = self.init_file_import()
|
|
312
312
|
if self.code_model.options["builders_visibility"] != "embedded":
|
|
313
313
|
group_name = request_builder.group_name
|
|
314
314
|
rest_import_path = "..." if async_mode else ".."
|
|
@@ -338,7 +338,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
338
338
|
self, async_mode: bool, **kwargs: Any
|
|
339
339
|
) -> FileImport:
|
|
340
340
|
if self.abstract:
|
|
341
|
-
return
|
|
341
|
+
return self.init_file_import()
|
|
342
342
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
343
343
|
|
|
344
344
|
for param in self.parameters.method:
|
|
@@ -379,11 +379,11 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
379
379
|
]
|
|
380
380
|
for error in errors:
|
|
381
381
|
file_import.add_submodule_import(
|
|
382
|
-
|
|
382
|
+
file_import.import_core_exceptions, error, ImportType.SDKCORE
|
|
383
383
|
)
|
|
384
384
|
if self.code_model.options["azure_arm"]:
|
|
385
385
|
file_import.add_submodule_import(
|
|
386
|
-
"azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.
|
|
386
|
+
"azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.SDKCORE
|
|
387
387
|
)
|
|
388
388
|
|
|
389
389
|
if self.has_kwargs_to_pop_with_default(
|
|
@@ -392,7 +392,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
392
392
|
self.parameters.kwargs_to_pop, ParameterLocation.QUERY # type: ignore
|
|
393
393
|
):
|
|
394
394
|
file_import.add_submodule_import(
|
|
395
|
-
|
|
395
|
+
file_import.import_core_utils,
|
|
396
|
+
"case_insensitive_dict",
|
|
397
|
+
ImportType.SDKCORE,
|
|
396
398
|
)
|
|
397
399
|
if self.deprecated:
|
|
398
400
|
file_import.add_import("warnings", ImportType.STDLIB)
|
|
@@ -404,7 +406,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
404
406
|
)
|
|
405
407
|
if self.has_etag:
|
|
406
408
|
file_import.add_submodule_import(
|
|
407
|
-
|
|
409
|
+
file_import.import_core_exceptions,
|
|
410
|
+
"ResourceModifiedError",
|
|
411
|
+
ImportType.SDKCORE,
|
|
408
412
|
)
|
|
409
413
|
if not async_mode:
|
|
410
414
|
file_import.add_submodule_import(
|
|
@@ -418,24 +422,26 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
418
422
|
file_import.add_submodule_import(
|
|
419
423
|
"azure.core.pipeline.transport",
|
|
420
424
|
"AsyncHttpResponse",
|
|
421
|
-
ImportType.
|
|
425
|
+
ImportType.SDKCORE,
|
|
422
426
|
)
|
|
423
427
|
else:
|
|
424
428
|
file_import.add_submodule_import(
|
|
425
429
|
"azure.core.pipeline.transport",
|
|
426
430
|
"HttpResponse",
|
|
427
|
-
ImportType.
|
|
431
|
+
ImportType.SDKCORE,
|
|
428
432
|
)
|
|
429
433
|
else:
|
|
430
434
|
if async_mode:
|
|
431
435
|
file_import.add_submodule_import(
|
|
432
|
-
|
|
436
|
+
file_import.import_core_rest,
|
|
433
437
|
"AsyncHttpResponse",
|
|
434
|
-
ImportType.
|
|
438
|
+
ImportType.SDKCORE,
|
|
435
439
|
)
|
|
436
440
|
else:
|
|
437
441
|
file_import.add_submodule_import(
|
|
438
|
-
|
|
442
|
+
file_import.import_core_rest,
|
|
443
|
+
"HttpResponse",
|
|
444
|
+
ImportType.SDKCORE,
|
|
439
445
|
)
|
|
440
446
|
if (
|
|
441
447
|
self.code_model.options["builders_visibility"] == "embedded"
|
|
@@ -443,10 +449,12 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
443
449
|
):
|
|
444
450
|
file_import.merge(self.request_builder.imports())
|
|
445
451
|
file_import.add_submodule_import(
|
|
446
|
-
|
|
452
|
+
file_import.import_core_pipeline,
|
|
453
|
+
"PipelineResponse",
|
|
454
|
+
ImportType.SDKCORE,
|
|
447
455
|
)
|
|
448
456
|
file_import.add_submodule_import(
|
|
449
|
-
|
|
457
|
+
file_import.import_core_rest, "HttpRequest", ImportType.SDKCORE
|
|
450
458
|
)
|
|
451
459
|
file_import.add_submodule_import(
|
|
452
460
|
"typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
@@ -464,7 +472,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
464
472
|
file_import.add_submodule_import(
|
|
465
473
|
"azure.core.tracing.decorator",
|
|
466
474
|
"distributed_trace",
|
|
467
|
-
ImportType.
|
|
475
|
+
ImportType.SDKCORE,
|
|
468
476
|
)
|
|
469
477
|
file_import.merge(
|
|
470
478
|
self.get_request_builder_import(self.request_builder, async_mode)
|
|
@@ -552,11 +560,11 @@ class Operation(OperationBase[Response]):
|
|
|
552
560
|
file_import = super().imports(async_mode, **kwargs)
|
|
553
561
|
if self.abstract:
|
|
554
562
|
return file_import
|
|
555
|
-
if async_mode:
|
|
563
|
+
if async_mode and self.code_model.options["tracing"] and self.want_tracing:
|
|
556
564
|
file_import.add_submodule_import(
|
|
557
565
|
"azure.core.tracing.decorator_async",
|
|
558
566
|
"distributed_trace_async",
|
|
559
|
-
ImportType.
|
|
567
|
+
ImportType.SDKCORE,
|
|
560
568
|
)
|
|
561
569
|
if (
|
|
562
570
|
self.has_response_body
|
|
@@ -48,7 +48,7 @@ class OperationGroup(BaseModel):
|
|
|
48
48
|
return ", ".join(base_classes)
|
|
49
49
|
|
|
50
50
|
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
51
|
-
file_import =
|
|
51
|
+
file_import = self.init_file_import()
|
|
52
52
|
relative_path = ".." if async_mode else "."
|
|
53
53
|
for operation in self.operations:
|
|
54
54
|
file_import.merge(
|
|
@@ -79,7 +79,7 @@ class OperationGroup(BaseModel):
|
|
|
79
79
|
return any(o for o in self.operations if o.need_validation)
|
|
80
80
|
|
|
81
81
|
def imports(self, async_mode: bool) -> FileImport:
|
|
82
|
-
file_import =
|
|
82
|
+
file_import = self.init_file_import()
|
|
83
83
|
|
|
84
84
|
relative_path = ("..." if async_mode else "..") + (
|
|
85
85
|
"." if self.client.is_subclient else ""
|
|
@@ -60,8 +60,14 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
60
60
|
else None
|
|
61
61
|
)
|
|
62
62
|
self.override_success_response_to_200 = override_success_response_to_200
|
|
63
|
-
self.pager_sync: str =
|
|
64
|
-
|
|
63
|
+
self.pager_sync: str = (
|
|
64
|
+
yaml_data.get("pagerSync")
|
|
65
|
+
or f"{self.init_file_import().import_core_paging}.ItemPaged"
|
|
66
|
+
)
|
|
67
|
+
self.pager_async: str = (
|
|
68
|
+
yaml_data.get("pagerAsync")
|
|
69
|
+
or f"{self.init_file_import().import_core_paging_async}.AsyncItemPaged"
|
|
70
|
+
)
|
|
65
71
|
|
|
66
72
|
def _get_attr_name(self, wire_name: str) -> str:
|
|
67
73
|
response_type = self.responses[0].type
|
|
@@ -144,14 +150,14 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
144
150
|
|
|
145
151
|
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
146
152
|
if self.abstract:
|
|
147
|
-
return
|
|
153
|
+
return self.init_file_import()
|
|
148
154
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
149
155
|
file_import.merge(super().imports(async_mode, **kwargs))
|
|
150
156
|
if self.code_model.options["tracing"] and self.want_tracing:
|
|
151
157
|
file_import.add_submodule_import(
|
|
152
158
|
"azure.core.tracing.decorator",
|
|
153
159
|
"distributed_trace",
|
|
154
|
-
ImportType.
|
|
160
|
+
ImportType.SDKCORE,
|
|
155
161
|
)
|
|
156
162
|
if self.next_request_builder:
|
|
157
163
|
file_import.merge(
|
|
@@ -160,7 +166,9 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
160
166
|
elif any(p.is_api_version for p in self.client.parameters):
|
|
161
167
|
file_import.add_import("urllib.parse", ImportType.STDLIB)
|
|
162
168
|
file_import.add_submodule_import(
|
|
163
|
-
|
|
169
|
+
file_import.import_core_utils,
|
|
170
|
+
"case_insensitive_dict",
|
|
171
|
+
ImportType.SDKCORE,
|
|
164
172
|
)
|
|
165
173
|
if self.code_model.options["models_mode"] == "dpg":
|
|
166
174
|
relative_path = "..." if async_mode else ".."
|
|
@@ -168,7 +168,7 @@ class _ParameterBase(
|
|
|
168
168
|
return self.type.serialization_type
|
|
169
169
|
|
|
170
170
|
def _imports_shared(self, async_mode: bool, **_: Any) -> FileImport:
|
|
171
|
-
file_import =
|
|
171
|
+
file_import = self.init_file_import()
|
|
172
172
|
if self.optional and self.client_default_value is None:
|
|
173
173
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
174
174
|
if self.added_on:
|