@autorest/python 6.44.0 → 6.45.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/generator/build/lib/pygen/codegen/models/property.py +1 -0
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +2 -0
- package/generator/build/lib/pygen/codegen/templates/macros.jinja2 +12 -5
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +28 -0
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/models/property.py +1 -0
- package/generator/pygen/codegen/serializers/model_serializer.py +2 -0
- package/generator/pygen/codegen/templates/macros.jinja2 +12 -5
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +28 -0
- package/package.json +2 -2
- package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
|
@@ -40,6 +40,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
40
40
|
self.is_multipart_file_input: bool = yaml_data.get("isMultipartFileInput", False)
|
|
41
41
|
self.flatten = self.yaml_data.get("flatten", False) and not getattr(self.type, "flattened_property", False)
|
|
42
42
|
self.original_tsp_name: Optional[str] = self.yaml_data.get("originalTspName")
|
|
43
|
+
self.encode: Optional[str] = self.yaml_data.get("encode")
|
|
43
44
|
|
|
44
45
|
def pylint_disable(self) -> str:
|
|
45
46
|
retval: str = ""
|
|
@@ -329,6 +329,8 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
329
329
|
args.append("is_multipart_file_input=True")
|
|
330
330
|
elif hasattr(prop.type, "encode") and prop.type.encode: # type: ignore
|
|
331
331
|
args.append(f'format="{prop.type.encode}"') # type: ignore
|
|
332
|
+
elif prop.encode:
|
|
333
|
+
args.append(f'format="{prop.encode}"')
|
|
332
334
|
|
|
333
335
|
if prop.xml_metadata:
|
|
334
336
|
args.append(f"xml={prop.xml_metadata}")
|
|
@@ -5,21 +5,28 @@
|
|
|
5
5
|
{% set enable_custom_handling = "\n* " in doc_string or doc_string.startswith("* ") %}
|
|
6
6
|
{%- if enable_custom_handling -%}
|
|
7
7
|
{%- set lines = doc_string.split('\n') -%}
|
|
8
|
+
{%- set base_indent = wrap_string.lstrip('\n') -%}
|
|
8
9
|
{%- set result_lines = [] -%}
|
|
9
10
|
{%- for line in lines -%}
|
|
10
11
|
{%- if line.startswith('* ') -%}
|
|
11
12
|
{# Handle bullet points with proper continuation alignment #}
|
|
12
13
|
{%- set bullet_content = line[2:] -%}
|
|
13
|
-
{%- set base_indent = wrap_string.lstrip('\n') -%}
|
|
14
14
|
{%- set bullet_line = base_indent + ' * ' + bullet_content -%}
|
|
15
15
|
{%- set continuation_spaces = base_indent + ' ' -%}
|
|
16
16
|
{%- set wrapped = bullet_line | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n' + continuation_spaces) -%}
|
|
17
17
|
{%- set _ = result_lines.append(wrapped) -%}
|
|
18
18
|
{%- elif line.strip() -%}
|
|
19
|
-
{%- set
|
|
20
|
-
{%- set
|
|
19
|
+
{%- set line_indent = '' if line.strip().startswith(':') or loop.index == 1 else (base_indent + ' ') -%}
|
|
20
|
+
{%- set wrapped = (line_indent + line) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrap_string) -%}
|
|
21
|
+
{%- for line in wrapped.split('\n') -%}
|
|
22
|
+
{%- set prefix = "" if loop.index == 1 else " " -%}
|
|
23
|
+
{%- set _ = result_lines.append(prefix + line) -%}
|
|
24
|
+
{%- endfor -%}
|
|
21
25
|
{%- else -%}
|
|
22
|
-
{
|
|
26
|
+
{# Do not add continuous blank lines #}
|
|
27
|
+
{%- if (result_lines and result_lines[-1] != '') or not result_lines -%}
|
|
28
|
+
{%- set _ = result_lines.append('') -%}
|
|
29
|
+
{%- endif -%}
|
|
23
30
|
{%- endif -%}
|
|
24
31
|
{%- endfor -%}
|
|
25
32
|
{%- set original_result = result_lines | join('\n') -%}
|
|
@@ -37,4 +44,4 @@
|
|
|
37
44
|
{% set suffix = suffix_string if list_result | length == loop.index %}
|
|
38
45
|
{{ prefix }}{{ line }}{{ suffix }}
|
|
39
46
|
{% endfor %}
|
|
40
|
-
{% endmacro %}
|
|
47
|
+
{% endmacro %}
|
|
@@ -179,6 +179,19 @@ _VALID_RFC7231 = re.compile(
|
|
|
179
179
|
r"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT"
|
|
180
180
|
)
|
|
181
181
|
|
|
182
|
+
_ARRAY_ENCODE_MAPPING = {
|
|
183
|
+
"pipeDelimited": "|",
|
|
184
|
+
"spaceDelimited": " ",
|
|
185
|
+
"commaDelimited": ",",
|
|
186
|
+
"newlineDelimited": "\n",
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
def _deserialize_array_encoded(delimit: str, attr):
|
|
190
|
+
if isinstance(attr, str):
|
|
191
|
+
if attr == "":
|
|
192
|
+
return []
|
|
193
|
+
return attr.split(delimit)
|
|
194
|
+
return attr
|
|
182
195
|
|
|
183
196
|
def _deserialize_datetime(attr: typing.Union[str, datetime]) -> datetime:
|
|
184
197
|
"""Deserialize ISO-8601 formatted string into Datetime object.
|
|
@@ -323,6 +336,8 @@ _DESERIALIZE_MAPPING_WITHFORMAT = {
|
|
|
323
336
|
def get_deserializer(annotation: typing.Any, rf: typing.Optional["_RestField"] = None):
|
|
324
337
|
if annotation is int and rf and rf._format == "str":
|
|
325
338
|
return _deserialize_int_as_str
|
|
339
|
+
if annotation is str and rf and rf._format in _ARRAY_ENCODE_MAPPING:
|
|
340
|
+
return functools.partial(_deserialize_array_encoded, _ARRAY_ENCODE_MAPPING[rf._format])
|
|
326
341
|
if rf and rf._format:
|
|
327
342
|
return _DESERIALIZE_MAPPING_WITHFORMAT.get(rf._format)
|
|
328
343
|
{% if code_model.has_external_type %}
|
|
@@ -497,6 +512,8 @@ def _is_model(obj: typing.Any) -> bool:
|
|
|
497
512
|
|
|
498
513
|
def _serialize(o, format: typing.Optional[str] = None): # pylint: disable=too-many-return-statements
|
|
499
514
|
if isinstance(o, list):
|
|
515
|
+
if format in _ARRAY_ENCODE_MAPPING and all(isinstance(x, str) for x in o):
|
|
516
|
+
return _ARRAY_ENCODE_MAPPING[format].join(o)
|
|
500
517
|
return [_serialize(x, format) for x in o]
|
|
501
518
|
if isinstance(o, dict):
|
|
502
519
|
return {k: _serialize(v, format) for k, v in o.items()}
|
|
@@ -809,6 +826,17 @@ def _deserialize_sequence(
|
|
|
809
826
|
return obj
|
|
810
827
|
if isinstance(obj, ET.Element):
|
|
811
828
|
obj = list(obj)
|
|
829
|
+
try:
|
|
830
|
+
if (
|
|
831
|
+
isinstance(obj, str)
|
|
832
|
+
and isinstance(deserializer, functools.partial)
|
|
833
|
+
and isinstance(deserializer.args[0], functools.partial)
|
|
834
|
+
and deserializer.args[0].func == _deserialize_array_encoded # pylint: disable=comparison-with-callable
|
|
835
|
+
):
|
|
836
|
+
# encoded string may be deserialized to sequence
|
|
837
|
+
return deserializer(obj)
|
|
838
|
+
except: # pylint: disable=bare-except
|
|
839
|
+
pass
|
|
812
840
|
return type(obj)(_deserialize(deserializer, entry, module) for entry in obj)
|
|
813
841
|
|
|
814
842
|
|
|
Binary file
|
|
@@ -40,6 +40,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
40
40
|
self.is_multipart_file_input: bool = yaml_data.get("isMultipartFileInput", False)
|
|
41
41
|
self.flatten = self.yaml_data.get("flatten", False) and not getattr(self.type, "flattened_property", False)
|
|
42
42
|
self.original_tsp_name: Optional[str] = self.yaml_data.get("originalTspName")
|
|
43
|
+
self.encode: Optional[str] = self.yaml_data.get("encode")
|
|
43
44
|
|
|
44
45
|
def pylint_disable(self) -> str:
|
|
45
46
|
retval: str = ""
|
|
@@ -329,6 +329,8 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
329
329
|
args.append("is_multipart_file_input=True")
|
|
330
330
|
elif hasattr(prop.type, "encode") and prop.type.encode: # type: ignore
|
|
331
331
|
args.append(f'format="{prop.type.encode}"') # type: ignore
|
|
332
|
+
elif prop.encode:
|
|
333
|
+
args.append(f'format="{prop.encode}"')
|
|
332
334
|
|
|
333
335
|
if prop.xml_metadata:
|
|
334
336
|
args.append(f"xml={prop.xml_metadata}")
|
|
@@ -5,21 +5,28 @@
|
|
|
5
5
|
{% set enable_custom_handling = "\n* " in doc_string or doc_string.startswith("* ") %}
|
|
6
6
|
{%- if enable_custom_handling -%}
|
|
7
7
|
{%- set lines = doc_string.split('\n') -%}
|
|
8
|
+
{%- set base_indent = wrap_string.lstrip('\n') -%}
|
|
8
9
|
{%- set result_lines = [] -%}
|
|
9
10
|
{%- for line in lines -%}
|
|
10
11
|
{%- if line.startswith('* ') -%}
|
|
11
12
|
{# Handle bullet points with proper continuation alignment #}
|
|
12
13
|
{%- set bullet_content = line[2:] -%}
|
|
13
|
-
{%- set base_indent = wrap_string.lstrip('\n') -%}
|
|
14
14
|
{%- set bullet_line = base_indent + ' * ' + bullet_content -%}
|
|
15
15
|
{%- set continuation_spaces = base_indent + ' ' -%}
|
|
16
16
|
{%- set wrapped = bullet_line | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n' + continuation_spaces) -%}
|
|
17
17
|
{%- set _ = result_lines.append(wrapped) -%}
|
|
18
18
|
{%- elif line.strip() -%}
|
|
19
|
-
{%- set
|
|
20
|
-
{%- set
|
|
19
|
+
{%- set line_indent = '' if line.strip().startswith(':') or loop.index == 1 else (base_indent + ' ') -%}
|
|
20
|
+
{%- set wrapped = (line_indent + line) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrap_string) -%}
|
|
21
|
+
{%- for line in wrapped.split('\n') -%}
|
|
22
|
+
{%- set prefix = "" if loop.index == 1 else " " -%}
|
|
23
|
+
{%- set _ = result_lines.append(prefix + line) -%}
|
|
24
|
+
{%- endfor -%}
|
|
21
25
|
{%- else -%}
|
|
22
|
-
{
|
|
26
|
+
{# Do not add continuous blank lines #}
|
|
27
|
+
{%- if (result_lines and result_lines[-1] != '') or not result_lines -%}
|
|
28
|
+
{%- set _ = result_lines.append('') -%}
|
|
29
|
+
{%- endif -%}
|
|
23
30
|
{%- endif -%}
|
|
24
31
|
{%- endfor -%}
|
|
25
32
|
{%- set original_result = result_lines | join('\n') -%}
|
|
@@ -37,4 +44,4 @@
|
|
|
37
44
|
{% set suffix = suffix_string if list_result | length == loop.index %}
|
|
38
45
|
{{ prefix }}{{ line }}{{ suffix }}
|
|
39
46
|
{% endfor %}
|
|
40
|
-
{% endmacro %}
|
|
47
|
+
{% endmacro %}
|
|
@@ -179,6 +179,19 @@ _VALID_RFC7231 = re.compile(
|
|
|
179
179
|
r"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT"
|
|
180
180
|
)
|
|
181
181
|
|
|
182
|
+
_ARRAY_ENCODE_MAPPING = {
|
|
183
|
+
"pipeDelimited": "|",
|
|
184
|
+
"spaceDelimited": " ",
|
|
185
|
+
"commaDelimited": ",",
|
|
186
|
+
"newlineDelimited": "\n",
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
def _deserialize_array_encoded(delimit: str, attr):
|
|
190
|
+
if isinstance(attr, str):
|
|
191
|
+
if attr == "":
|
|
192
|
+
return []
|
|
193
|
+
return attr.split(delimit)
|
|
194
|
+
return attr
|
|
182
195
|
|
|
183
196
|
def _deserialize_datetime(attr: typing.Union[str, datetime]) -> datetime:
|
|
184
197
|
"""Deserialize ISO-8601 formatted string into Datetime object.
|
|
@@ -323,6 +336,8 @@ _DESERIALIZE_MAPPING_WITHFORMAT = {
|
|
|
323
336
|
def get_deserializer(annotation: typing.Any, rf: typing.Optional["_RestField"] = None):
|
|
324
337
|
if annotation is int and rf and rf._format == "str":
|
|
325
338
|
return _deserialize_int_as_str
|
|
339
|
+
if annotation is str and rf and rf._format in _ARRAY_ENCODE_MAPPING:
|
|
340
|
+
return functools.partial(_deserialize_array_encoded, _ARRAY_ENCODE_MAPPING[rf._format])
|
|
326
341
|
if rf and rf._format:
|
|
327
342
|
return _DESERIALIZE_MAPPING_WITHFORMAT.get(rf._format)
|
|
328
343
|
{% if code_model.has_external_type %}
|
|
@@ -497,6 +512,8 @@ def _is_model(obj: typing.Any) -> bool:
|
|
|
497
512
|
|
|
498
513
|
def _serialize(o, format: typing.Optional[str] = None): # pylint: disable=too-many-return-statements
|
|
499
514
|
if isinstance(o, list):
|
|
515
|
+
if format in _ARRAY_ENCODE_MAPPING and all(isinstance(x, str) for x in o):
|
|
516
|
+
return _ARRAY_ENCODE_MAPPING[format].join(o)
|
|
500
517
|
return [_serialize(x, format) for x in o]
|
|
501
518
|
if isinstance(o, dict):
|
|
502
519
|
return {k: _serialize(v, format) for k, v in o.items()}
|
|
@@ -809,6 +826,17 @@ def _deserialize_sequence(
|
|
|
809
826
|
return obj
|
|
810
827
|
if isinstance(obj, ET.Element):
|
|
811
828
|
obj = list(obj)
|
|
829
|
+
try:
|
|
830
|
+
if (
|
|
831
|
+
isinstance(obj, str)
|
|
832
|
+
and isinstance(deserializer, functools.partial)
|
|
833
|
+
and isinstance(deserializer.args[0], functools.partial)
|
|
834
|
+
and deserializer.args[0].func == _deserialize_array_encoded # pylint: disable=comparison-with-callable
|
|
835
|
+
):
|
|
836
|
+
# encoded string may be deserialized to sequence
|
|
837
|
+
return deserializer(obj)
|
|
838
|
+
except: # pylint: disable=bare-except
|
|
839
|
+
pass
|
|
812
840
|
return type(obj)(_deserialize(deserializer, entry, module) for entry in obj)
|
|
813
841
|
|
|
814
842
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autorest/python",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.45.0",
|
|
4
4
|
"description": "The Python extension for generators in AutoRest.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@typespec/http-client-python": "~0.
|
|
22
|
+
"@typespec/http-client-python": "~0.23.0",
|
|
23
23
|
"@autorest/system-requirements": "~1.0.2",
|
|
24
24
|
"fs-extra": "~11.2.0",
|
|
25
25
|
"tsx": "~4.19.1"
|
|
Binary file
|