@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
|
@@ -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:
|
|
@@ -107,7 +107,7 @@ class BinaryType(PrimitiveType):
|
|
|
107
107
|
from .combined_type import CombinedType
|
|
108
108
|
from .operation import OperationBase
|
|
109
109
|
|
|
110
|
-
file_import =
|
|
110
|
+
file_import = self.init_file_import()
|
|
111
111
|
file_import.add_submodule_import("typing", "IO", ImportType.STDLIB)
|
|
112
112
|
operation = kwargs.get("operation")
|
|
113
113
|
if (
|
|
@@ -145,7 +145,7 @@ class BinaryIteratorType(PrimitiveType):
|
|
|
145
145
|
return self.get_declaration("Iterator[bytes]")
|
|
146
146
|
|
|
147
147
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
148
|
-
file_import =
|
|
148
|
+
file_import = self.init_file_import()
|
|
149
149
|
iterator = "AsyncIterator" if kwargs.get("async_mode") else "Iterator"
|
|
150
150
|
file_import.add_submodule_import("typing", iterator, ImportType.STDLIB)
|
|
151
151
|
return file_import
|
|
@@ -171,7 +171,7 @@ class AnyType(PrimitiveType):
|
|
|
171
171
|
return self.get_declaration({})
|
|
172
172
|
|
|
173
173
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
174
|
-
file_import =
|
|
174
|
+
file_import = self.init_file_import()
|
|
175
175
|
file_import.add_submodule_import(
|
|
176
176
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
177
177
|
)
|
|
@@ -204,7 +204,7 @@ class AnyObjectType(PrimitiveType):
|
|
|
204
204
|
return "isinstance({}, MutableMapping)"
|
|
205
205
|
|
|
206
206
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
207
|
-
file_import =
|
|
207
|
+
file_import = self.init_file_import()
|
|
208
208
|
file_import.define_mutable_mapping_type()
|
|
209
209
|
return file_import
|
|
210
210
|
|
|
@@ -386,7 +386,7 @@ class DatetimeType(PrimitiveType):
|
|
|
386
386
|
return f'"{value}"'
|
|
387
387
|
|
|
388
388
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
389
|
-
file_import =
|
|
389
|
+
file_import = self.init_file_import()
|
|
390
390
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
391
391
|
return file_import
|
|
392
392
|
|
|
@@ -398,9 +398,8 @@ class DatetimeType(PrimitiveType):
|
|
|
398
398
|
def instance_check_template(self) -> str:
|
|
399
399
|
return "isinstance({}, datetime.datetime)"
|
|
400
400
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
file_import = super(DatetimeType, DatetimeType).imports_for_sample()
|
|
401
|
+
def imports_for_sample(self) -> FileImport:
|
|
402
|
+
file_import = super().imports_for_sample()
|
|
404
403
|
file_import.add_import("isodate", ImportType.STDLIB)
|
|
405
404
|
return file_import
|
|
406
405
|
|
|
@@ -430,7 +429,7 @@ class TimeType(PrimitiveType):
|
|
|
430
429
|
return f'"{value}"'
|
|
431
430
|
|
|
432
431
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
433
|
-
file_import =
|
|
432
|
+
file_import = self.init_file_import()
|
|
434
433
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
435
434
|
return file_import
|
|
436
435
|
|
|
@@ -442,9 +441,8 @@ class TimeType(PrimitiveType):
|
|
|
442
441
|
def instance_check_template(self) -> str:
|
|
443
442
|
return "isinstance({}, datetime.time)"
|
|
444
443
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
file_import = super(TimeType, TimeType).imports_for_sample()
|
|
444
|
+
def imports_for_sample(self) -> FileImport:
|
|
445
|
+
file_import = super().imports_for_sample()
|
|
448
446
|
file_import.add_import("isodate", ImportType.STDLIB)
|
|
449
447
|
return file_import
|
|
450
448
|
|
|
@@ -478,7 +476,7 @@ class UnixTimeType(PrimitiveType):
|
|
|
478
476
|
return f'"{value}"'
|
|
479
477
|
|
|
480
478
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
481
|
-
file_import =
|
|
479
|
+
file_import = self.init_file_import()
|
|
482
480
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
483
481
|
return file_import
|
|
484
482
|
|
|
@@ -490,9 +488,8 @@ class UnixTimeType(PrimitiveType):
|
|
|
490
488
|
def instance_check_template(self) -> str:
|
|
491
489
|
return "isinstance({}, datetime.time)"
|
|
492
490
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
file_import = super(UnixTimeType, UnixTimeType).imports_for_sample()
|
|
491
|
+
def imports_for_sample(self) -> FileImport:
|
|
492
|
+
file_import = super().imports_for_sample()
|
|
496
493
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
497
494
|
return file_import
|
|
498
495
|
|
|
@@ -522,7 +519,7 @@ class DateType(PrimitiveType):
|
|
|
522
519
|
return f'"{value}"'
|
|
523
520
|
|
|
524
521
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
525
|
-
file_import =
|
|
522
|
+
file_import = self.init_file_import()
|
|
526
523
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
527
524
|
return file_import
|
|
528
525
|
|
|
@@ -534,9 +531,8 @@ class DateType(PrimitiveType):
|
|
|
534
531
|
def instance_check_template(self) -> str:
|
|
535
532
|
return "isinstance({}, datetime.date)"
|
|
536
533
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
file_import = super(DateType, DateType).imports_for_sample()
|
|
534
|
+
def imports_for_sample(self) -> FileImport:
|
|
535
|
+
file_import = super().imports_for_sample()
|
|
540
536
|
file_import.add_import("isodate", ImportType.STDLIB)
|
|
541
537
|
return file_import
|
|
542
538
|
|
|
@@ -566,7 +562,7 @@ class DurationType(PrimitiveType):
|
|
|
566
562
|
return f'"{value}"'
|
|
567
563
|
|
|
568
564
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
569
|
-
file_import =
|
|
565
|
+
file_import = self.init_file_import()
|
|
570
566
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
571
567
|
return file_import
|
|
572
568
|
|
|
@@ -578,9 +574,8 @@ class DurationType(PrimitiveType):
|
|
|
578
574
|
def instance_check_template(self) -> str:
|
|
579
575
|
return "isinstance({}, datetime.timedelta)"
|
|
580
576
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
file_import = super(DurationType, DurationType).imports_for_sample()
|
|
577
|
+
def imports_for_sample(self) -> FileImport:
|
|
578
|
+
file_import = super().imports_for_sample()
|
|
584
579
|
file_import.add_import("isodate", ImportType.STDLIB)
|
|
585
580
|
return file_import
|
|
586
581
|
|
|
@@ -611,20 +606,24 @@ class ByteArraySchema(PrimitiveType):
|
|
|
611
606
|
return "isinstance({}, bytes)"
|
|
612
607
|
|
|
613
608
|
|
|
614
|
-
class
|
|
609
|
+
class SdkCoreType(PrimitiveType):
|
|
615
610
|
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
616
611
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
617
612
|
self.name = yaml_data.get("name", "")
|
|
618
613
|
|
|
619
614
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
620
|
-
return "~
|
|
615
|
+
return f"~{self.init_file_import().import_core}" + self.type_annotation(
|
|
616
|
+
**kwargs
|
|
617
|
+
)
|
|
621
618
|
|
|
622
619
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
623
620
|
return self.name
|
|
624
621
|
|
|
625
622
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
626
|
-
file_import =
|
|
627
|
-
file_import.add_submodule_import(
|
|
623
|
+
file_import = self.init_file_import()
|
|
624
|
+
file_import.add_submodule_import(
|
|
625
|
+
file_import.import_core, self.name, ImportType.SDKCORE
|
|
626
|
+
)
|
|
628
627
|
return file_import
|
|
629
628
|
|
|
630
629
|
@property
|
|
@@ -120,6 +120,8 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
120
120
|
)
|
|
121
121
|
if self.description(is_operation_file=True):
|
|
122
122
|
description = self.description(is_operation_file=True)
|
|
123
|
+
# make sure there is no \n otherwise the json template will be invalid
|
|
124
|
+
description = (description or "").replace("\n", " ")
|
|
123
125
|
return self.type.get_json_template_representation(
|
|
124
126
|
optional=self.optional,
|
|
125
127
|
client_default_value_declaration=client_default_value_declaration,
|
|
@@ -145,7 +147,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
145
147
|
return retval or None
|
|
146
148
|
|
|
147
149
|
def imports(self, **kwargs) -> FileImport:
|
|
148
|
-
file_import =
|
|
150
|
+
file_import = self.init_file_import()
|
|
149
151
|
if self.is_discriminator and isinstance(self.type, EnumType):
|
|
150
152
|
return file_import
|
|
151
153
|
file_import.merge(
|
|
@@ -72,16 +72,16 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
72
72
|
|
|
73
73
|
def response_docstring_text(self, **kwargs) -> str:
|
|
74
74
|
return (
|
|
75
|
-
"Returns an :class:`~
|
|
75
|
+
f"Returns an :class:`~{self.response_docstring_type()}` that you will pass to the client's "
|
|
76
76
|
+ "`send_request` method. See https://aka.ms/azsdk/dpcodegen/python/send_request for how to "
|
|
77
77
|
+ "incorporate this response into your code flow."
|
|
78
78
|
)
|
|
79
79
|
|
|
80
80
|
def response_docstring_type(self, **kwargs) -> str:
|
|
81
|
-
return "~
|
|
81
|
+
return f"~{self.init_file_import().import_core_rest}.HttpRequest"
|
|
82
82
|
|
|
83
83
|
def imports(self) -> FileImport:
|
|
84
|
-
file_import =
|
|
84
|
+
file_import = self.init_file_import()
|
|
85
85
|
relative_path = ".."
|
|
86
86
|
if (
|
|
87
87
|
not self.code_model.options["builders_visibility"] == "embedded"
|
|
@@ -98,28 +98,29 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
98
98
|
)
|
|
99
99
|
|
|
100
100
|
file_import.add_submodule_import(
|
|
101
|
-
|
|
101
|
+
file_import.import_core_rest,
|
|
102
102
|
"HttpRequest",
|
|
103
|
-
ImportType.
|
|
103
|
+
ImportType.SDKCORE,
|
|
104
104
|
)
|
|
105
105
|
|
|
106
106
|
if self.parameters.headers or self.parameters.query:
|
|
107
107
|
file_import.add_submodule_import(
|
|
108
|
-
|
|
108
|
+
file_import.import_core_utils,
|
|
109
|
+
"case_insensitive_dict",
|
|
110
|
+
ImportType.SDKCORE,
|
|
109
111
|
)
|
|
110
112
|
file_import.add_submodule_import(
|
|
111
113
|
"typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL
|
|
112
114
|
)
|
|
113
115
|
file_import.add_msrest_import(
|
|
114
|
-
|
|
115
|
-
"..."
|
|
116
|
+
relative_path="..."
|
|
116
117
|
if (
|
|
117
118
|
not self.code_model.options["builders_visibility"] == "embedded"
|
|
118
119
|
and self.group_name
|
|
119
120
|
)
|
|
120
121
|
else "..",
|
|
121
|
-
MsrestImportType.Serializer,
|
|
122
|
-
TypingSection.REGULAR,
|
|
122
|
+
msrest_import_type=MsrestImportType.Serializer,
|
|
123
|
+
typing_section=TypingSection.REGULAR,
|
|
123
124
|
)
|
|
124
125
|
if (
|
|
125
126
|
self.overloads
|
|
@@ -8,7 +8,7 @@ from typing import Dict, Optional, List, Any, TYPE_CHECKING, Union
|
|
|
8
8
|
from .base import BaseModel
|
|
9
9
|
from .base import BaseType
|
|
10
10
|
from .imports import FileImport, ImportType, TypingSection
|
|
11
|
-
from .primitive_types import BinaryType, BinaryIteratorType
|
|
11
|
+
from .primitive_types import BinaryType, BinaryIteratorType, ByteArraySchema
|
|
12
12
|
from .dictionary_type import DictionaryType
|
|
13
13
|
from .list_type import ListType
|
|
14
14
|
from .model_type import ModelType
|
|
@@ -58,6 +58,7 @@ class Response(BaseModel):
|
|
|
58
58
|
self.headers = headers or []
|
|
59
59
|
self.type = type
|
|
60
60
|
self.nullable = yaml_data.get("nullable")
|
|
61
|
+
self.default_content_type = yaml_data.get("defaultContentType")
|
|
61
62
|
|
|
62
63
|
@property
|
|
63
64
|
def result_property(self) -> str:
|
|
@@ -80,7 +81,12 @@ class Response(BaseModel):
|
|
|
80
81
|
@property
|
|
81
82
|
def is_stream_response(self) -> bool:
|
|
82
83
|
"""Is the response expected to be streamable, like a download."""
|
|
83
|
-
|
|
84
|
+
retval = isinstance(self.type, BinaryIteratorType) or (
|
|
85
|
+
isinstance(self.type, ByteArraySchema)
|
|
86
|
+
and bool(self.default_content_type)
|
|
87
|
+
and self.default_content_type != "application/json"
|
|
88
|
+
)
|
|
89
|
+
return retval
|
|
84
90
|
|
|
85
91
|
@property
|
|
86
92
|
def serialization_type(self) -> str:
|
|
@@ -108,7 +114,7 @@ class Response(BaseModel):
|
|
|
108
114
|
return self.type.docstring_type(**kwargs) if self.type else "None"
|
|
109
115
|
|
|
110
116
|
def _imports_shared(self, **kwargs: Any) -> FileImport:
|
|
111
|
-
file_import =
|
|
117
|
+
file_import = self.init_file_import()
|
|
112
118
|
if self.type:
|
|
113
119
|
file_import.merge(self.type.imports(**kwargs))
|
|
114
120
|
if self.nullable:
|
|
@@ -158,6 +164,14 @@ class PagingResponse(Response):
|
|
|
158
164
|
def __init__(self, *args, **kwargs) -> None:
|
|
159
165
|
super().__init__(*args, **kwargs)
|
|
160
166
|
self.item_type = self.code_model.lookup_type(id(self.yaml_data["itemType"]))
|
|
167
|
+
self.pager_sync: str = (
|
|
168
|
+
self.yaml_data.get("pagerSync")
|
|
169
|
+
or f"{self.init_file_import().import_core_paging}.ItemPaged"
|
|
170
|
+
)
|
|
171
|
+
self.pager_async: str = (
|
|
172
|
+
self.yaml_data.get("pagerAsync")
|
|
173
|
+
or f"{self.init_file_import().import_core_paging_async}.AsyncItemPaged"
|
|
174
|
+
)
|
|
161
175
|
|
|
162
176
|
def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
|
|
163
177
|
return self.item_type.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
@@ -166,9 +180,7 @@ class PagingResponse(Response):
|
|
|
166
180
|
return self.item_type.get_json_template_representation()
|
|
167
181
|
|
|
168
182
|
def get_pager_path(self, async_mode: bool) -> str:
|
|
169
|
-
return
|
|
170
|
-
self.yaml_data["pagerAsync"] if async_mode else self.yaml_data["pagerSync"]
|
|
171
|
-
)
|
|
183
|
+
return self.pager_async if async_mode else self.pager_sync
|
|
172
184
|
|
|
173
185
|
def get_pager(self, async_mode: bool) -> str:
|
|
174
186
|
return self.get_pager_path(async_mode).split(".")[-1]
|
|
@@ -192,7 +204,7 @@ class PagingResponse(Response):
|
|
|
192
204
|
pager_import_path = ".".join(self.get_pager_path(async_mode).split(".")[:-1])
|
|
193
205
|
pager = self.get_pager(async_mode)
|
|
194
206
|
|
|
195
|
-
file_import.add_submodule_import(pager_import_path, pager, ImportType.
|
|
207
|
+
file_import.add_submodule_import(pager_import_path, pager, ImportType.SDKCORE)
|
|
196
208
|
return file_import
|
|
197
209
|
|
|
198
210
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
@@ -200,7 +212,9 @@ class PagingResponse(Response):
|
|
|
200
212
|
async_mode = kwargs.get("async_mode")
|
|
201
213
|
if async_mode:
|
|
202
214
|
file_import.add_submodule_import(
|
|
203
|
-
|
|
215
|
+
file_import.import_core_paging_async,
|
|
216
|
+
"AsyncList",
|
|
217
|
+
ImportType.SDKCORE,
|
|
204
218
|
)
|
|
205
219
|
|
|
206
220
|
return file_import
|
|
@@ -269,9 +283,7 @@ class LROResponse(Response):
|
|
|
269
283
|
async_mode = kwargs["async_mode"]
|
|
270
284
|
poller_import_path = ".".join(self.get_poller_path(async_mode).split(".")[:-1])
|
|
271
285
|
poller = self.get_poller(async_mode)
|
|
272
|
-
file_import.add_submodule_import(
|
|
273
|
-
poller_import_path, poller, ImportType.AZURECORE
|
|
274
|
-
)
|
|
286
|
+
file_import.add_submodule_import(poller_import_path, poller, ImportType.SDKCORE)
|
|
275
287
|
return file_import
|
|
276
288
|
|
|
277
289
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
@@ -285,7 +297,7 @@ class LROResponse(Response):
|
|
|
285
297
|
file_import.add_submodule_import(
|
|
286
298
|
default_polling_method_import_path,
|
|
287
299
|
default_polling_method,
|
|
288
|
-
ImportType.
|
|
300
|
+
ImportType.SDKCORE,
|
|
289
301
|
)
|
|
290
302
|
default_no_polling_method_import_path = ".".join(
|
|
291
303
|
self.get_no_polling_method_path(async_mode).split(".")[:-1]
|
|
@@ -294,7 +306,7 @@ class LROResponse(Response):
|
|
|
294
306
|
file_import.add_submodule_import(
|
|
295
307
|
default_no_polling_method_import_path,
|
|
296
308
|
default_no_polling_method,
|
|
297
|
-
ImportType.
|
|
309
|
+
ImportType.SDKCORE,
|
|
298
310
|
)
|
|
299
311
|
|
|
300
312
|
base_polling_method_import_path = ".".join(
|
|
@@ -302,7 +314,7 @@ class LROResponse(Response):
|
|
|
302
314
|
)
|
|
303
315
|
base_polling_method = self.get_base_polling_method(async_mode)
|
|
304
316
|
file_import.add_submodule_import(
|
|
305
|
-
base_polling_method_import_path, base_polling_method, ImportType.
|
|
317
|
+
base_polling_method_import_path, base_polling_method, ImportType.SDKCORE
|
|
306
318
|
)
|
|
307
319
|
return file_import
|
|
308
320
|
|
|
@@ -240,6 +240,11 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
240
240
|
serializer = GeneralSerializer(self.code_model, env, async_mode=False)
|
|
241
241
|
params = self.code_model.options["package_configuration"] or {}
|
|
242
242
|
for template_name in package_files:
|
|
243
|
+
if (
|
|
244
|
+
self.code_model.options["unbranded"]
|
|
245
|
+
and template_name == "dev_requirements.txt.jinja2"
|
|
246
|
+
):
|
|
247
|
+
continue
|
|
243
248
|
file = template_name.replace(".jinja2", "")
|
|
244
249
|
output_name = root_of_sdk / file
|
|
245
250
|
if not self.read_file(output_name) or file in _REGENERATE_FILES:
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
from jinja2 import Environment
|
|
7
|
+
from ..models import (
|
|
8
|
+
FileImport,
|
|
9
|
+
CodeModel,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BaseSerializer:
|
|
14
|
+
"""Base serializer for SDK root level files"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, code_model: CodeModel, env: Environment):
|
|
17
|
+
self.code_model = code_model
|
|
18
|
+
self.env = env
|
|
19
|
+
|
|
20
|
+
def init_file_import(self) -> FileImport:
|
|
21
|
+
return FileImport(self.code_model)
|
|
@@ -426,6 +426,12 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
426
426
|
builder.parameters.path, self.serializer_name
|
|
427
427
|
)
|
|
428
428
|
|
|
429
|
+
@property
|
|
430
|
+
def pipeline_name(self) -> str:
|
|
431
|
+
if not self.code_model.options["unbranded"]:
|
|
432
|
+
return "_pipeline"
|
|
433
|
+
return "pipeline"
|
|
434
|
+
|
|
429
435
|
|
|
430
436
|
############################## REQUEST BUILDERS ##############################
|
|
431
437
|
|
|
@@ -483,12 +489,13 @@ class RequestBuilderSerializer(
|
|
|
483
489
|
return False
|
|
484
490
|
|
|
485
491
|
def response_docstring(self, builder: RequestBuilderType) -> List[str]:
|
|
492
|
+
import_core_rest = builder.init_file_import().import_core_rest
|
|
486
493
|
response_str = (
|
|
487
|
-
":return: Returns an :class:`~
|
|
494
|
+
f":return: Returns an :class:`~{import_core_rest}.HttpRequest` that you will pass to the client's "
|
|
488
495
|
+ "`send_request` method. See https://aka.ms/azsdk/dpcodegen/python/send_request for how to "
|
|
489
496
|
+ "incorporate this response into your code flow."
|
|
490
497
|
)
|
|
491
|
-
rtype_str = ":rtype: ~
|
|
498
|
+
rtype_str = f":rtype: ~{import_core_rest}.HttpRequest"
|
|
492
499
|
return [response_str, rtype_str]
|
|
493
500
|
|
|
494
501
|
def pop_kwargs_from_signature(self, builder: RequestBuilderType) -> List[str]:
|
|
@@ -637,13 +644,13 @@ class _OperationSerializer(
|
|
|
637
644
|
def make_pipeline_call(self, builder: OperationType) -> List[str]:
|
|
638
645
|
type_ignore = self.async_mode and builder.group_name == "" # is in a mixin
|
|
639
646
|
stream_value = (
|
|
640
|
-
'kwargs.pop("stream",
|
|
647
|
+
f'kwargs.pop("stream", {builder.has_stream_response})'
|
|
641
648
|
if builder.expose_stream_keyword
|
|
642
649
|
else builder.has_stream_response
|
|
643
650
|
)
|
|
644
651
|
return [
|
|
645
652
|
f"_stream = {stream_value}",
|
|
646
|
-
f"pipeline_response: PipelineResponse = {self._call_method}self._client.
|
|
653
|
+
f"pipeline_response: PipelineResponse = {self._call_method}self._client.{self.pipeline_name}.run( "
|
|
647
654
|
+ f"{'# type: ignore' if type_ignore else ''} # pylint: disable=protected-access",
|
|
648
655
|
" _request,",
|
|
649
656
|
" stream=_stream,",
|
|
@@ -723,7 +730,7 @@ class _OperationSerializer(
|
|
|
723
730
|
return [
|
|
724
731
|
response_str,
|
|
725
732
|
rtype_str,
|
|
726
|
-
":raises ~
|
|
733
|
+
f":raises ~{builder.init_file_import().import_core_exceptions}.HttpResponseError:",
|
|
727
734
|
]
|
|
728
735
|
|
|
729
736
|
def _serialize_body_parameter(self, builder: OperationType) -> List[str]:
|
|
@@ -1049,14 +1056,17 @@ class _OperationSerializer(
|
|
|
1049
1056
|
if response.headers:
|
|
1050
1057
|
retval.append("")
|
|
1051
1058
|
deserialize_code: List[str] = []
|
|
1052
|
-
if
|
|
1053
|
-
|
|
1054
|
-
"
|
|
1059
|
+
if builder.has_stream_response:
|
|
1060
|
+
if isinstance(response.type, ByteArraySchema):
|
|
1061
|
+
retval.append(f"{'await ' if self.async_mode else ''}response.read()")
|
|
1062
|
+
deserialized = "response.content"
|
|
1063
|
+
else:
|
|
1064
|
+
deserialized = (
|
|
1055
1065
|
"response.iter_bytes()"
|
|
1056
1066
|
if self.code_model.options["version_tolerant"]
|
|
1057
|
-
else "response.stream_download(self._client.
|
|
1067
|
+
else f"response.stream_download(self._client.{self.pipeline_name})"
|
|
1058
1068
|
)
|
|
1059
|
-
)
|
|
1069
|
+
deserialize_code.append(f"deserialized = {deserialized}")
|
|
1060
1070
|
elif response.type:
|
|
1061
1071
|
pylint_disable = ""
|
|
1062
1072
|
if isinstance(response.type, ModelType) and response.type.internal:
|
|
@@ -1069,14 +1079,18 @@ class _OperationSerializer(
|
|
|
1069
1079
|
deserialize_code.append(" pipeline_response")
|
|
1070
1080
|
deserialize_code.append(")")
|
|
1071
1081
|
elif self.code_model.options["models_mode"] == "dpg":
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1082
|
+
if builder.has_stream_response:
|
|
1083
|
+
deserialize_code.append("deserialized = response.content")
|
|
1084
|
+
else:
|
|
1085
|
+
deserialize_code.append("deserialized = _deserialize(")
|
|
1086
|
+
deserialize_code.append(
|
|
1087
|
+
f" {response.type.type_annotation(is_operation_file=True)},{pylint_disable}"
|
|
1088
|
+
)
|
|
1089
|
+
deserialize_code.append(
|
|
1090
|
+
f" response.json(){response.result_property}"
|
|
1091
|
+
)
|
|
1092
|
+
deserialize_code.append(")")
|
|
1093
|
+
|
|
1080
1094
|
else:
|
|
1081
1095
|
deserialized_value = (
|
|
1082
1096
|
"ET.fromstring(response.text())"
|
|
@@ -1088,7 +1102,7 @@ class _OperationSerializer(
|
|
|
1088
1102
|
deserialize_code.append("else:")
|
|
1089
1103
|
deserialize_code.append(" deserialized = None")
|
|
1090
1104
|
if len(deserialize_code) > 0:
|
|
1091
|
-
if builder.expose_stream_keyword:
|
|
1105
|
+
if builder.expose_stream_keyword and not builder.has_stream_response:
|
|
1092
1106
|
retval.append("if _stream:")
|
|
1093
1107
|
retval.append(" deserialized = response.iter_bytes()")
|
|
1094
1108
|
retval.append("else:")
|
|
@@ -1565,7 +1579,7 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1565
1579
|
retval.append("else: polling_method = polling")
|
|
1566
1580
|
retval.append("if cont_token:")
|
|
1567
1581
|
retval.append(
|
|
1568
|
-
f" return {builder.
|
|
1582
|
+
f" return {builder.get_poller_with_response_type(self.async_mode)}.from_continuation_token("
|
|
1569
1583
|
)
|
|
1570
1584
|
retval.append(" polling_method=polling_method,")
|
|
1571
1585
|
retval.append(" continuation_token=cont_token,")
|
|
@@ -1573,9 +1587,12 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1573
1587
|
retval.append(" deserialization_callback=get_long_running_output")
|
|
1574
1588
|
retval.append(" )")
|
|
1575
1589
|
retval.append(
|
|
1576
|
-
f"return {builder.
|
|
1577
|
-
"(self._client, raw_result, get_long_running_output, polling_method) # type: ignore"
|
|
1590
|
+
f"return {builder.get_poller_with_response_type(self.async_mode)}("
|
|
1578
1591
|
)
|
|
1592
|
+
retval.append(
|
|
1593
|
+
" self._client, raw_result, get_long_running_output, polling_method # type: ignore"
|
|
1594
|
+
)
|
|
1595
|
+
retval.append(" )")
|
|
1579
1596
|
return retval
|
|
1580
1597
|
|
|
1581
1598
|
def get_long_running_output(self, builder: LROOperationType) -> List[str]:
|
|
@@ -111,19 +111,28 @@ class ClientSerializer:
|
|
|
111
111
|
def initialize_pipeline_client(self, async_mode: bool) -> List[str]:
|
|
112
112
|
result = []
|
|
113
113
|
pipeline_client_name = self.client.pipeline_class(async_mode)
|
|
114
|
+
endpoint_name = (
|
|
115
|
+
"endpoint" if self.client.code_model.options["unbranded"] else "base_url"
|
|
116
|
+
)
|
|
114
117
|
params = {
|
|
115
|
-
|
|
118
|
+
endpoint_name: self.host_variable_name,
|
|
116
119
|
"policies": "_policies",
|
|
117
120
|
}
|
|
118
121
|
if not self.client.code_model.is_legacy and self.client.request_id_header_name:
|
|
119
122
|
result.append(
|
|
120
123
|
f'kwargs["request_id_header_name"] = "{self.client.request_id_header_name}"'
|
|
121
124
|
)
|
|
125
|
+
policies = build_policies(
|
|
126
|
+
self.client.code_model.options["azure_arm"],
|
|
127
|
+
async_mode,
|
|
128
|
+
self.client.code_model.options["unbranded"],
|
|
129
|
+
self.client.code_model.options["tracing"],
|
|
130
|
+
)
|
|
122
131
|
result.extend(
|
|
123
132
|
[
|
|
124
133
|
"_policies = kwargs.pop('policies', None)",
|
|
125
134
|
"if _policies is None:",
|
|
126
|
-
f' _policies = [{",".join(
|
|
135
|
+
f' _policies = [{",".join(policies)}]',
|
|
127
136
|
f"self._client: {pipeline_client_name} = {pipeline_client_name}("
|
|
128
137
|
f"{', '.join(f'{k}={v}' for k, v in params.items())}, **kwargs)",
|
|
129
138
|
]
|
|
@@ -243,7 +252,9 @@ class ClientSerializer:
|
|
|
243
252
|
return retval
|
|
244
253
|
|
|
245
254
|
def _rest_request_example(self, async_mode: bool) -> List[str]:
|
|
246
|
-
retval = [
|
|
255
|
+
retval = [
|
|
256
|
+
f">>> from {self.client.init_file_import().import_core_rest} import HttpRequest"
|
|
257
|
+
]
|
|
247
258
|
retval.append('>>> request = HttpRequest("GET", "https://www.example.org/")')
|
|
248
259
|
retval.append("<HttpRequest [GET], url: 'https://www.example.org/'>")
|
|
249
260
|
retval.extend(self._example_make_call(async_mode))
|
|
@@ -262,7 +273,9 @@ class ClientSerializer:
|
|
|
262
273
|
)
|
|
263
274
|
retval.append("")
|
|
264
275
|
retval.append(":param request: The network request you want to make. Required.")
|
|
265
|
-
retval.append(
|
|
276
|
+
retval.append(
|
|
277
|
+
f":type request: ~{self.client.init_file_import().import_core_rest}.HttpRequest"
|
|
278
|
+
)
|
|
266
279
|
retval.append(
|
|
267
280
|
":keyword bool stream: Whether the response payload will be streamed. Defaults to False."
|
|
268
281
|
)
|
|
@@ -270,7 +283,9 @@ class ClientSerializer:
|
|
|
270
283
|
":return: The response of your network call. Does not do error handling on your response."
|
|
271
284
|
)
|
|
272
285
|
http_response = "AsyncHttpResponse" if async_mode else "HttpResponse"
|
|
273
|
-
retval.append(
|
|
286
|
+
retval.append(
|
|
287
|
+
f":rtype: ~{self.client.init_file_import().import_core_rest}.{http_response}"
|
|
288
|
+
)
|
|
274
289
|
retval.append('"""')
|
|
275
290
|
return retval
|
|
276
291
|
|