methodaws 0.0.17__tar.gz → 0.0.19__tar.gz
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.
- {methodaws-0.0.17 → methodaws-0.0.19}/PKG-INFO +1 -1
- {methodaws-0.0.17 → methodaws-0.0.19}/pyproject.toml +1 -1
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/core/pydantic_utilities.py +72 -29
- methodaws-0.0.19/src/methodaws/core/serialization.py +254 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/load_balancer_v_1.py +1 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/load_balancer_v_2.py +1 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/bucket.py +1 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/s_3_report.py +0 -1
- methodaws-0.0.17/src/methodaws/core/serialization.py +0 -170
- {methodaws-0.0.17 → methodaws-0.0.19}/README.md +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/__init__.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/core/__init__.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/core/datetime_utils.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/py.typed +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/__init__.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/credential/__init__.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/credential/credential_info.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/credential/credential_report.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/__init__.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/certificate.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/ip_address_type.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/listener.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/load_balancer_report.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/load_balancer_state.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/protocol.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/target.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/target_group.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/target_group_ip_address_type.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/target_type.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/__init__.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/bucket_versioning_status.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/encryption_rule.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/external_bucket.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/external_s_3_report.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/s_3_bucket_acl.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/s_3_mfa_delete_status.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/s_3_object_details.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/s_3_public_access_block_configuration.py +0 -0
- {methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/s_3_server_side_encryption.py +0 -0
|
@@ -10,6 +10,7 @@ import typing_extensions
|
|
|
10
10
|
import pydantic
|
|
11
11
|
|
|
12
12
|
from .datetime_utils import serialize_datetime
|
|
13
|
+
from .serialization import convert_and_respect_annotation_metadata
|
|
13
14
|
|
|
14
15
|
IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
|
|
15
16
|
|
|
@@ -56,11 +57,12 @@ Model = typing.TypeVar("Model", bound=pydantic.BaseModel)
|
|
|
56
57
|
|
|
57
58
|
|
|
58
59
|
def parse_obj_as(type_: typing.Type[T], object_: typing.Any) -> T:
|
|
60
|
+
dealiased_object = convert_and_respect_annotation_metadata(object_=object_, annotation=type_, direction="read")
|
|
59
61
|
if IS_PYDANTIC_V2:
|
|
60
62
|
adapter = pydantic.TypeAdapter(type_) # type: ignore # Pydantic v2
|
|
61
|
-
return adapter.validate_python(
|
|
63
|
+
return adapter.validate_python(dealiased_object)
|
|
62
64
|
else:
|
|
63
|
-
return pydantic.parse_obj_as(type_,
|
|
65
|
+
return pydantic.parse_obj_as(type_, dealiased_object)
|
|
64
66
|
|
|
65
67
|
|
|
66
68
|
def to_jsonable_with_fallback(
|
|
@@ -75,11 +77,16 @@ def to_jsonable_with_fallback(
|
|
|
75
77
|
|
|
76
78
|
|
|
77
79
|
class UniversalBaseModel(pydantic.BaseModel):
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
if IS_PYDANTIC_V2:
|
|
81
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
82
|
+
protected_namespaces=(),
|
|
83
|
+
json_encoders={dt.datetime: serialize_datetime},
|
|
84
|
+
) # type: ignore # Pydantic v2
|
|
85
|
+
else:
|
|
86
|
+
|
|
87
|
+
class Config:
|
|
88
|
+
smart_union = True
|
|
89
|
+
json_encoders = {dt.datetime: serialize_datetime}
|
|
83
90
|
|
|
84
91
|
def json(self, **kwargs: typing.Any) -> str:
|
|
85
92
|
kwargs_with_defaults: typing.Any = {
|
|
@@ -97,30 +104,66 @@ class UniversalBaseModel(pydantic.BaseModel):
|
|
|
97
104
|
Override the default dict method to `exclude_unset` by default. This function patches
|
|
98
105
|
`exclude_unset` to work include fields within non-None default values.
|
|
99
106
|
"""
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
for
|
|
104
|
-
|
|
105
|
-
default = _get_field_default(field)
|
|
106
|
-
|
|
107
|
-
# If the default values are non-null act like they've been set
|
|
108
|
-
# This effectively allows exclude_unset to work like exclude_none where
|
|
109
|
-
# the latter passes through intentionally set none values.
|
|
110
|
-
if default != None:
|
|
111
|
-
_fields_set.add(name)
|
|
112
|
-
|
|
113
|
-
kwargs_with_defaults_exclude_unset: typing.Any = {
|
|
114
|
-
"by_alias": True,
|
|
115
|
-
"exclude_unset": True,
|
|
116
|
-
"include": _fields_set,
|
|
117
|
-
**kwargs,
|
|
118
|
-
}
|
|
119
|
-
|
|
107
|
+
# Note: the logic here is multi-plexed given the levers exposed in Pydantic V1 vs V2
|
|
108
|
+
# Pydantic V1's .dict can be extremely slow, so we do not want to call it twice.
|
|
109
|
+
#
|
|
110
|
+
# We'd ideally do the same for Pydantic V2, but it shells out to a library to serialize models
|
|
111
|
+
# that we have less control over, and this is less intrusive than custom serializers for now.
|
|
120
112
|
if IS_PYDANTIC_V2:
|
|
121
|
-
|
|
113
|
+
kwargs_with_defaults_exclude_unset: typing.Any = {
|
|
114
|
+
**kwargs,
|
|
115
|
+
"by_alias": True,
|
|
116
|
+
"exclude_unset": True,
|
|
117
|
+
"exclude_none": False,
|
|
118
|
+
}
|
|
119
|
+
kwargs_with_defaults_exclude_none: typing.Any = {
|
|
120
|
+
**kwargs,
|
|
121
|
+
"by_alias": True,
|
|
122
|
+
"exclude_none": True,
|
|
123
|
+
"exclude_unset": False,
|
|
124
|
+
}
|
|
125
|
+
dict_dump = deep_union_pydantic_dicts(
|
|
126
|
+
super().model_dump(**kwargs_with_defaults_exclude_unset), # type: ignore # Pydantic v2
|
|
127
|
+
super().model_dump(**kwargs_with_defaults_exclude_none), # type: ignore # Pydantic v2
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
else:
|
|
131
|
+
_fields_set = self.__fields_set__
|
|
132
|
+
|
|
133
|
+
fields = _get_model_fields(self.__class__)
|
|
134
|
+
for name, field in fields.items():
|
|
135
|
+
if name not in _fields_set:
|
|
136
|
+
default = _get_field_default(field)
|
|
137
|
+
|
|
138
|
+
# If the default values are non-null act like they've been set
|
|
139
|
+
# This effectively allows exclude_unset to work like exclude_none where
|
|
140
|
+
# the latter passes through intentionally set none values.
|
|
141
|
+
if default != None:
|
|
142
|
+
_fields_set.add(name)
|
|
143
|
+
|
|
144
|
+
kwargs_with_defaults_exclude_unset_include_fields: typing.Any = {
|
|
145
|
+
"by_alias": True,
|
|
146
|
+
"exclude_unset": True,
|
|
147
|
+
"include": _fields_set,
|
|
148
|
+
**kwargs,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
dict_dump = super().dict(**kwargs_with_defaults_exclude_unset_include_fields)
|
|
152
|
+
|
|
153
|
+
return convert_and_respect_annotation_metadata(object_=dict_dump, annotation=self.__class__, direction="write")
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def deep_union_pydantic_dicts(
|
|
157
|
+
source: typing.Dict[str, typing.Any], destination: typing.Dict[str, typing.Any]
|
|
158
|
+
) -> typing.Dict[str, typing.Any]:
|
|
159
|
+
for key, value in source.items():
|
|
160
|
+
if isinstance(value, dict):
|
|
161
|
+
node = destination.setdefault(key, {})
|
|
162
|
+
deep_union_pydantic_dicts(value, node)
|
|
122
163
|
else:
|
|
123
|
-
|
|
164
|
+
destination[key] = value
|
|
165
|
+
|
|
166
|
+
return destination
|
|
124
167
|
|
|
125
168
|
|
|
126
169
|
if IS_PYDANTIC_V2:
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import collections
|
|
4
|
+
import inspect
|
|
5
|
+
import typing
|
|
6
|
+
|
|
7
|
+
import typing_extensions
|
|
8
|
+
|
|
9
|
+
import pydantic
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class FieldMetadata:
|
|
13
|
+
"""
|
|
14
|
+
Metadata class used to annotate fields to provide additional information.
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
class MyDict(TypedDict):
|
|
18
|
+
field: typing.Annotated[str, FieldMetadata(alias="field_name")]
|
|
19
|
+
|
|
20
|
+
Will serialize: `{"field": "value"}`
|
|
21
|
+
To: `{"field_name": "value"}`
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
alias: str
|
|
25
|
+
|
|
26
|
+
def __init__(self, *, alias: str) -> None:
|
|
27
|
+
self.alias = alias
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def convert_and_respect_annotation_metadata(
|
|
31
|
+
*,
|
|
32
|
+
object_: typing.Any,
|
|
33
|
+
annotation: typing.Any,
|
|
34
|
+
inner_type: typing.Optional[typing.Any] = None,
|
|
35
|
+
direction: typing.Literal["read", "write"],
|
|
36
|
+
) -> typing.Any:
|
|
37
|
+
"""
|
|
38
|
+
Respect the metadata annotations on a field, such as aliasing. This function effectively
|
|
39
|
+
manipulates the dict-form of an object to respect the metadata annotations. This is primarily used for
|
|
40
|
+
TypedDicts, which cannot support aliasing out of the box, and can be extended for additional
|
|
41
|
+
utilities, such as defaults.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
object_ : typing.Any
|
|
46
|
+
|
|
47
|
+
annotation : type
|
|
48
|
+
The type we're looking to apply typing annotations from
|
|
49
|
+
|
|
50
|
+
inner_type : typing.Optional[type]
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
typing.Any
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
if object_ is None:
|
|
58
|
+
return None
|
|
59
|
+
if inner_type is None:
|
|
60
|
+
inner_type = annotation
|
|
61
|
+
|
|
62
|
+
clean_type = _remove_annotations(inner_type)
|
|
63
|
+
# Pydantic models
|
|
64
|
+
if (
|
|
65
|
+
inspect.isclass(clean_type)
|
|
66
|
+
and issubclass(clean_type, pydantic.BaseModel)
|
|
67
|
+
and isinstance(object_, typing.Mapping)
|
|
68
|
+
):
|
|
69
|
+
return _convert_mapping(object_, clean_type, direction)
|
|
70
|
+
# TypedDicts
|
|
71
|
+
if typing_extensions.is_typeddict(clean_type) and isinstance(object_, typing.Mapping):
|
|
72
|
+
return _convert_mapping(object_, clean_type, direction)
|
|
73
|
+
|
|
74
|
+
# If you're iterating on a string, do not bother to coerce it to a sequence.
|
|
75
|
+
if not isinstance(object_, str):
|
|
76
|
+
if (
|
|
77
|
+
typing_extensions.get_origin(clean_type) == typing.Set
|
|
78
|
+
or typing_extensions.get_origin(clean_type) == set
|
|
79
|
+
or clean_type == typing.Set
|
|
80
|
+
) and isinstance(object_, typing.Set):
|
|
81
|
+
inner_type = typing_extensions.get_args(clean_type)[0]
|
|
82
|
+
return {
|
|
83
|
+
convert_and_respect_annotation_metadata(
|
|
84
|
+
object_=item,
|
|
85
|
+
annotation=annotation,
|
|
86
|
+
inner_type=inner_type,
|
|
87
|
+
direction=direction,
|
|
88
|
+
)
|
|
89
|
+
for item in object_
|
|
90
|
+
}
|
|
91
|
+
elif (
|
|
92
|
+
(
|
|
93
|
+
typing_extensions.get_origin(clean_type) == typing.List
|
|
94
|
+
or typing_extensions.get_origin(clean_type) == list
|
|
95
|
+
or clean_type == typing.List
|
|
96
|
+
)
|
|
97
|
+
and isinstance(object_, typing.List)
|
|
98
|
+
) or (
|
|
99
|
+
(
|
|
100
|
+
typing_extensions.get_origin(clean_type) == typing.Sequence
|
|
101
|
+
or typing_extensions.get_origin(clean_type) == collections.abc.Sequence
|
|
102
|
+
or clean_type == typing.Sequence
|
|
103
|
+
)
|
|
104
|
+
and isinstance(object_, typing.Sequence)
|
|
105
|
+
):
|
|
106
|
+
inner_type = typing_extensions.get_args(clean_type)[0]
|
|
107
|
+
return [
|
|
108
|
+
convert_and_respect_annotation_metadata(
|
|
109
|
+
object_=item,
|
|
110
|
+
annotation=annotation,
|
|
111
|
+
inner_type=inner_type,
|
|
112
|
+
direction=direction,
|
|
113
|
+
)
|
|
114
|
+
for item in object_
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
if typing_extensions.get_origin(clean_type) == typing.Union:
|
|
118
|
+
# We should be able to ~relatively~ safely try to convert keys against all
|
|
119
|
+
# member types in the union, the edge case here is if one member aliases a field
|
|
120
|
+
# of the same name to a different name from another member
|
|
121
|
+
# Or if another member aliases a field of the same name that another member does not.
|
|
122
|
+
for member in typing_extensions.get_args(clean_type):
|
|
123
|
+
object_ = convert_and_respect_annotation_metadata(
|
|
124
|
+
object_=object_,
|
|
125
|
+
annotation=annotation,
|
|
126
|
+
inner_type=member,
|
|
127
|
+
direction=direction,
|
|
128
|
+
)
|
|
129
|
+
return object_
|
|
130
|
+
|
|
131
|
+
annotated_type = _get_annotation(annotation)
|
|
132
|
+
if annotated_type is None:
|
|
133
|
+
return object_
|
|
134
|
+
|
|
135
|
+
# If the object is not a TypedDict, a Union, or other container (list, set, sequence, etc.)
|
|
136
|
+
# Then we can safely call it on the recursive conversion.
|
|
137
|
+
return object_
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _convert_mapping(
|
|
141
|
+
object_: typing.Mapping[str, object],
|
|
142
|
+
expected_type: typing.Any,
|
|
143
|
+
direction: typing.Literal["read", "write"],
|
|
144
|
+
) -> typing.Mapping[str, object]:
|
|
145
|
+
converted_object: typing.Dict[str, object] = {}
|
|
146
|
+
annotations = typing_extensions.get_type_hints(expected_type, include_extras=True)
|
|
147
|
+
aliases_to_field_names = _get_alias_to_field_name(annotations)
|
|
148
|
+
for key, value in object_.items():
|
|
149
|
+
if direction == "read" and key in aliases_to_field_names:
|
|
150
|
+
dealiased_key = aliases_to_field_names.get(key)
|
|
151
|
+
if dealiased_key is not None:
|
|
152
|
+
type_ = annotations.get(dealiased_key)
|
|
153
|
+
else:
|
|
154
|
+
type_ = annotations.get(key)
|
|
155
|
+
# Note you can't get the annotation by the field name if you're in read mode, so you must check the aliases map
|
|
156
|
+
#
|
|
157
|
+
# So this is effectively saying if we're in write mode, and we don't have a type, or if we're in read mode and we don't have an alias
|
|
158
|
+
# then we can just pass the value through as is
|
|
159
|
+
if type_ is None:
|
|
160
|
+
converted_object[key] = value
|
|
161
|
+
elif direction == "read" and key not in aliases_to_field_names:
|
|
162
|
+
converted_object[key] = convert_and_respect_annotation_metadata(
|
|
163
|
+
object_=value, annotation=type_, direction=direction
|
|
164
|
+
)
|
|
165
|
+
else:
|
|
166
|
+
converted_object[_alias_key(key, type_, direction, aliases_to_field_names)] = (
|
|
167
|
+
convert_and_respect_annotation_metadata(object_=value, annotation=type_, direction=direction)
|
|
168
|
+
)
|
|
169
|
+
return converted_object
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _get_annotation(type_: typing.Any) -> typing.Optional[typing.Any]:
|
|
173
|
+
maybe_annotated_type = typing_extensions.get_origin(type_)
|
|
174
|
+
if maybe_annotated_type is None:
|
|
175
|
+
return None
|
|
176
|
+
|
|
177
|
+
if maybe_annotated_type == typing_extensions.NotRequired:
|
|
178
|
+
type_ = typing_extensions.get_args(type_)[0]
|
|
179
|
+
maybe_annotated_type = typing_extensions.get_origin(type_)
|
|
180
|
+
|
|
181
|
+
if maybe_annotated_type == typing_extensions.Annotated:
|
|
182
|
+
return type_
|
|
183
|
+
|
|
184
|
+
return None
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _remove_annotations(type_: typing.Any) -> typing.Any:
|
|
188
|
+
maybe_annotated_type = typing_extensions.get_origin(type_)
|
|
189
|
+
if maybe_annotated_type is None:
|
|
190
|
+
return type_
|
|
191
|
+
|
|
192
|
+
if maybe_annotated_type == typing_extensions.NotRequired:
|
|
193
|
+
return _remove_annotations(typing_extensions.get_args(type_)[0])
|
|
194
|
+
|
|
195
|
+
if maybe_annotated_type == typing_extensions.Annotated:
|
|
196
|
+
return _remove_annotations(typing_extensions.get_args(type_)[0])
|
|
197
|
+
|
|
198
|
+
return type_
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def get_alias_to_field_mapping(type_: typing.Any) -> typing.Dict[str, str]:
|
|
202
|
+
annotations = typing_extensions.get_type_hints(type_, include_extras=True)
|
|
203
|
+
return _get_alias_to_field_name(annotations)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def get_field_to_alias_mapping(type_: typing.Any) -> typing.Dict[str, str]:
|
|
207
|
+
annotations = typing_extensions.get_type_hints(type_, include_extras=True)
|
|
208
|
+
return _get_field_to_alias_name(annotations)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _get_alias_to_field_name(
|
|
212
|
+
field_to_hint: typing.Dict[str, typing.Any],
|
|
213
|
+
) -> typing.Dict[str, str]:
|
|
214
|
+
aliases = {}
|
|
215
|
+
for field, hint in field_to_hint.items():
|
|
216
|
+
maybe_alias = _get_alias_from_type(hint)
|
|
217
|
+
if maybe_alias is not None:
|
|
218
|
+
aliases[maybe_alias] = field
|
|
219
|
+
return aliases
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _get_field_to_alias_name(
|
|
223
|
+
field_to_hint: typing.Dict[str, typing.Any],
|
|
224
|
+
) -> typing.Dict[str, str]:
|
|
225
|
+
aliases = {}
|
|
226
|
+
for field, hint in field_to_hint.items():
|
|
227
|
+
maybe_alias = _get_alias_from_type(hint)
|
|
228
|
+
if maybe_alias is not None:
|
|
229
|
+
aliases[field] = maybe_alias
|
|
230
|
+
return aliases
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _get_alias_from_type(type_: typing.Any) -> typing.Optional[str]:
|
|
234
|
+
maybe_annotated_type = _get_annotation(type_)
|
|
235
|
+
|
|
236
|
+
if maybe_annotated_type is not None:
|
|
237
|
+
# The actual annotations are 1 onward, the first is the annotated type
|
|
238
|
+
annotations = typing_extensions.get_args(maybe_annotated_type)[1:]
|
|
239
|
+
|
|
240
|
+
for annotation in annotations:
|
|
241
|
+
if isinstance(annotation, FieldMetadata) and annotation.alias is not None:
|
|
242
|
+
return annotation.alias
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _alias_key(
|
|
247
|
+
key: str,
|
|
248
|
+
type_: typing.Any,
|
|
249
|
+
direction: typing.Literal["read", "write"],
|
|
250
|
+
aliases_to_field_names: typing.Dict[str, str],
|
|
251
|
+
) -> str:
|
|
252
|
+
if direction == "read":
|
|
253
|
+
return aliases_to_field_names.get(key, key)
|
|
254
|
+
return _get_alias_from_type(type_=type_) or key
|
{methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/load_balancer_v_1.py
RENAMED
|
@@ -11,6 +11,7 @@ from ...core.pydantic_utilities import IS_PYDANTIC_V2
|
|
|
11
11
|
|
|
12
12
|
class LoadBalancerV1(UniversalBaseModel):
|
|
13
13
|
name: str
|
|
14
|
+
region: str
|
|
14
15
|
created_time: dt.datetime = pydantic.Field(alias="createdTime")
|
|
15
16
|
dns_name: str = pydantic.Field(alias="dnsName")
|
|
16
17
|
security_group_ids: typing.Optional[typing.List[str]] = pydantic.Field(alias="securityGroupIds", default=None)
|
{methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/load_balancer_v_2.py
RENAMED
|
@@ -19,6 +19,7 @@ class LoadBalancerV2(UniversalBaseModel):
|
|
|
19
19
|
|
|
20
20
|
arn: str
|
|
21
21
|
name: str
|
|
22
|
+
region: str
|
|
22
23
|
created_time: dt.datetime = pydantic.Field(alias="createdTime")
|
|
23
24
|
dns_name: str = pydantic.Field(alias="dnsName")
|
|
24
25
|
ip_address_type: IpAddressType = pydantic.Field(alias="ipAddressType")
|
|
@@ -9,7 +9,6 @@ from ...core.pydantic_utilities import IS_PYDANTIC_V2
|
|
|
9
9
|
|
|
10
10
|
class S3Report(UniversalBaseModel):
|
|
11
11
|
account_id: str = pydantic.Field(alias="accountId")
|
|
12
|
-
region: str
|
|
13
12
|
s_3_buckets: typing.Optional[typing.List[Bucket]] = pydantic.Field(alias="s3Buckets", default=None)
|
|
14
13
|
errors: typing.Optional[typing.List[str]] = None
|
|
15
14
|
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import collections
|
|
4
|
-
import typing
|
|
5
|
-
|
|
6
|
-
import typing_extensions
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class FieldMetadata:
|
|
10
|
-
"""
|
|
11
|
-
Metadata class used to annotate fields to provide additional information.
|
|
12
|
-
|
|
13
|
-
Example:
|
|
14
|
-
class MyDict(TypedDict):
|
|
15
|
-
field: typing.Annotated[str, FieldMetadata(alias="field_name")]
|
|
16
|
-
|
|
17
|
-
Will serialize: `{"field": "value"}`
|
|
18
|
-
To: `{"field_name": "value"}`
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
alias: str
|
|
22
|
-
|
|
23
|
-
def __init__(self, *, alias: str) -> None:
|
|
24
|
-
self.alias = alias
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def convert_and_respect_annotation_metadata(
|
|
28
|
-
*,
|
|
29
|
-
object_: typing.Any,
|
|
30
|
-
annotation: typing.Any,
|
|
31
|
-
inner_type: typing.Optional[typing.Any] = None,
|
|
32
|
-
) -> typing.Any:
|
|
33
|
-
"""
|
|
34
|
-
Respect the metadata annotations on a field, such as aliasing. This function effectively
|
|
35
|
-
manipulates the dict-form of an object to respect the metadata annotations. This is primarily used for
|
|
36
|
-
TypedDicts, which cannot support aliasing out of the box, and can be extended for additional
|
|
37
|
-
utilities, such as defaults.
|
|
38
|
-
|
|
39
|
-
Parameters
|
|
40
|
-
----------
|
|
41
|
-
object_ : typing.Any
|
|
42
|
-
|
|
43
|
-
annotation : type
|
|
44
|
-
The type we're looking to apply typing annotations from
|
|
45
|
-
|
|
46
|
-
inner_type : typing.Optional[type]
|
|
47
|
-
|
|
48
|
-
Returns
|
|
49
|
-
-------
|
|
50
|
-
typing.Any
|
|
51
|
-
"""
|
|
52
|
-
|
|
53
|
-
if object_ is None:
|
|
54
|
-
return None
|
|
55
|
-
if inner_type is None:
|
|
56
|
-
inner_type = annotation
|
|
57
|
-
|
|
58
|
-
clean_type = _remove_annotations(inner_type)
|
|
59
|
-
if typing_extensions.is_typeddict(clean_type) and isinstance(object_, typing.Mapping):
|
|
60
|
-
return _convert_typeddict(object_, clean_type)
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
# If you're iterating on a string, do not bother to coerce it to a sequence.
|
|
64
|
-
(not isinstance(object_, str))
|
|
65
|
-
and (
|
|
66
|
-
(
|
|
67
|
-
(
|
|
68
|
-
typing_extensions.get_origin(clean_type) == typing.List
|
|
69
|
-
or typing_extensions.get_origin(clean_type) == list
|
|
70
|
-
or clean_type == typing.List
|
|
71
|
-
)
|
|
72
|
-
and isinstance(object_, typing.List)
|
|
73
|
-
)
|
|
74
|
-
or (
|
|
75
|
-
(
|
|
76
|
-
typing_extensions.get_origin(clean_type) == typing.Set
|
|
77
|
-
or typing_extensions.get_origin(clean_type) == set
|
|
78
|
-
or clean_type == typing.Set
|
|
79
|
-
)
|
|
80
|
-
and isinstance(object_, typing.Set)
|
|
81
|
-
)
|
|
82
|
-
or (
|
|
83
|
-
(
|
|
84
|
-
typing_extensions.get_origin(clean_type) == typing.Sequence
|
|
85
|
-
or typing_extensions.get_origin(clean_type) == collections.abc.Sequence
|
|
86
|
-
or clean_type == typing.Sequence
|
|
87
|
-
)
|
|
88
|
-
and isinstance(object_, typing.Sequence)
|
|
89
|
-
)
|
|
90
|
-
)
|
|
91
|
-
):
|
|
92
|
-
inner_type = typing_extensions.get_args(clean_type)[0]
|
|
93
|
-
return [
|
|
94
|
-
convert_and_respect_annotation_metadata(object_=item, annotation=annotation, inner_type=inner_type)
|
|
95
|
-
for item in object_
|
|
96
|
-
]
|
|
97
|
-
|
|
98
|
-
if typing_extensions.get_origin(clean_type) == typing.Union:
|
|
99
|
-
# We should be able to ~relatively~ safely try to convert keys against all
|
|
100
|
-
# member types in the union, the edge case here is if one member aliases a field
|
|
101
|
-
# of the same name to a different name from another member
|
|
102
|
-
# Or if another member aliases a field of the same name that another member does not.
|
|
103
|
-
for member in typing_extensions.get_args(clean_type):
|
|
104
|
-
object_ = convert_and_respect_annotation_metadata(object_=object_, annotation=annotation, inner_type=member)
|
|
105
|
-
return object_
|
|
106
|
-
|
|
107
|
-
annotated_type = _get_annotation(annotation)
|
|
108
|
-
if annotated_type is None:
|
|
109
|
-
return object_
|
|
110
|
-
|
|
111
|
-
# If the object is not a TypedDict, a Union, or other container (list, set, sequence, etc.)
|
|
112
|
-
# Then we can safely call it on the recursive conversion.
|
|
113
|
-
return object_
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def _convert_typeddict(object_: typing.Mapping[str, object], expected_type: typing.Any) -> typing.Mapping[str, object]:
|
|
117
|
-
converted_object: typing.Dict[str, object] = {}
|
|
118
|
-
annotations = typing_extensions.get_type_hints(expected_type, include_extras=True)
|
|
119
|
-
for key, value in object_.items():
|
|
120
|
-
type_ = annotations.get(key)
|
|
121
|
-
if type_ is None:
|
|
122
|
-
converted_object[key] = value
|
|
123
|
-
else:
|
|
124
|
-
converted_object[_alias_key(key, type_)] = convert_and_respect_annotation_metadata(
|
|
125
|
-
object_=value, annotation=type_
|
|
126
|
-
)
|
|
127
|
-
return converted_object
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
def _get_annotation(type_: typing.Any) -> typing.Optional[typing.Any]:
|
|
131
|
-
maybe_annotated_type = typing_extensions.get_origin(type_)
|
|
132
|
-
if maybe_annotated_type is None:
|
|
133
|
-
return None
|
|
134
|
-
|
|
135
|
-
if maybe_annotated_type == typing_extensions.NotRequired:
|
|
136
|
-
type_ = typing_extensions.get_args(type_)[0]
|
|
137
|
-
maybe_annotated_type = typing_extensions.get_origin(type_)
|
|
138
|
-
|
|
139
|
-
if maybe_annotated_type == typing_extensions.Annotated:
|
|
140
|
-
return type_
|
|
141
|
-
|
|
142
|
-
return None
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def _remove_annotations(type_: typing.Any) -> typing.Any:
|
|
146
|
-
maybe_annotated_type = typing_extensions.get_origin(type_)
|
|
147
|
-
if maybe_annotated_type is None:
|
|
148
|
-
return type_
|
|
149
|
-
|
|
150
|
-
if maybe_annotated_type == typing_extensions.NotRequired:
|
|
151
|
-
return _remove_annotations(typing_extensions.get_args(type_)[0])
|
|
152
|
-
|
|
153
|
-
if maybe_annotated_type == typing_extensions.Annotated:
|
|
154
|
-
return _remove_annotations(typing_extensions.get_args(type_)[0])
|
|
155
|
-
|
|
156
|
-
return type_
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def _alias_key(key: str, type_: typing.Any) -> str:
|
|
160
|
-
maybe_annotated_type = _get_annotation(type_)
|
|
161
|
-
|
|
162
|
-
if maybe_annotated_type is not None:
|
|
163
|
-
# The actual annotations are 1 onward, the first is the annotated type
|
|
164
|
-
annotations = typing_extensions.get_args(maybe_annotated_type)[1:]
|
|
165
|
-
|
|
166
|
-
for annotation in annotations:
|
|
167
|
-
if isinstance(annotation, FieldMetadata) and annotation.alias is not None:
|
|
168
|
-
return annotation.alias
|
|
169
|
-
|
|
170
|
-
return key
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/credential/credential_report.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/ip_address_type.py
RENAMED
|
File without changes
|
|
File without changes
|
{methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/load_balancer_report.py
RENAMED
|
File without changes
|
{methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/loadbalancer/load_balancer_state.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/bucket_versioning_status.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{methodaws-0.0.17 → methodaws-0.0.19}/src/methodaws/resources/s_3/s_3_server_side_encryption.py
RENAMED
|
File without changes
|