in src/smexperiments/_boto_functions.py [0:0]
def from_boto(boto_dict, boto_name_to_member_name, member_name_to_type):
"""
Convert an UpperCamelCase boto response to a snake case representation.
Args:
boto_dict (dict[str, ?]): A boto response dictionary.
boto_name_to_member_name (dict[str, str]): A map from boto name to snake_case name. If a given boto name is
not in the map then a default mapping is applied.
member_name_to_type (dict[str, (_base_types.ApiObject, boolean)]): A map from snake case name to a type
description tuple. The first element of the tuple, a subclass of ApiObject, is the type of the mapped
object. The second element indicates whether the mapped element is a collection or singleton.
Returns:
dict: Boto response in snake case.
"""
from_boto_values = {}
for boto_name, boto_value in boto_dict.items():
# Convert the boto_name to a snake-case name by preferentially looking up the boto name in
# boto_name_to_member_name before defaulting to the snake case representation
member_name = boto_name_to_member_name.get(boto_name, to_snake_case(boto_name))
# If the member name maps to a subclass of _base_types.ApiObject (i.e. it's in member_name_to_type), then
# transform its boto dictionary using that type:
if member_name in member_name_to_type:
api_type, is_collection = member_name_to_type[member_name]
if is_collection:
if isinstance(boto_value, dict):
member_value = {key: api_type.from_boto(value) for key, value in boto_value.items()}
else:
member_value = [api_type.from_boto(item) for item in boto_value]
else:
member_value = api_type.from_boto(boto_value)
# If the member name does not have a custom type definition then simply assign it the boto value.
# Appropriate if the type is simple and requires not further conversion (e.g. a number or list of strings).
else:
member_value = boto_value
from_boto_values[member_name] = member_value
return from_boto_values