Пример #1
0
    def _serialize_list(_attribute):
        # type: (dynamodb_types.LIST) -> bytes
        """
        :param list _attribute: Attribute to serialize
        :returns: Serialized _attribute
        :rtype: bytes
        """
        serialized_attribute = io.BytesIO()
        serialized_attribute.write(_RESERVED)
        serialized_attribute.write(Tag.LIST.tag)
        serialized_attribute.write(encode_length(_attribute))
        for member in _attribute:
            serialized_attribute.write(serialize_attribute(member))

        return serialized_attribute.getvalue()
Пример #2
0
    def _serialize_list(_attribute):
        # type: (dynamodb_types.LIST) -> bytes
        # pylint: disable=no-member
        # for some reason pylint can't follow the Enum member attributes
        """
        :param list _attribute: Attribute to serialize
        :returns: Serialized _attribute
        :rtype: bytes
        """
        serialized_attribute = io.BytesIO()
        serialized_attribute.write(_RESERVED)
        serialized_attribute.write(Tag.LIST.tag)
        serialized_attribute.write(encode_length(_attribute))
        for member in _attribute:
            serialized_attribute.write(serialize_attribute(member))

        return serialized_attribute.getvalue()
Пример #3
0
    def _serialize_map(_attribute):
        # type: (dynamodb_types.MAP) -> bytes
        """
        :param list _attribute: Attribute to serialize
        :returns: Serialized _attribute
        :rtype: bytes
        """
        serialized_attribute = io.BytesIO()
        serialized_attribute.write(_RESERVED)
        serialized_attribute.write(Tag.MAP.tag)
        serialized_attribute.write(encode_length(_attribute))

        sorted_items = _sorted_key_map(item=_attribute,
                                       transform=_transform_string_value)

        for key, value, _original_key in sorted_items:
            serialized_attribute.write(_serialize_string(key))
            serialized_attribute.write(serialize_attribute(value))

        return serialized_attribute.getvalue()
Пример #4
0
    def _serialize_map(_attribute):
        # type: (dynamodb_types.MAP) -> bytes
        """
        :param list _attribute: Attribute to serialize
        :returns: Serialized _attribute
        :rtype: bytes
        """
        serialized_attribute = io.BytesIO()
        serialized_attribute.write(_RESERVED)
        # for some reason pylint can't follow the Enum member attributes
        serialized_attribute.write(Tag.MAP.tag)  # pylint: disable=no-member
        serialized_attribute.write(encode_length(_attribute))

        sorted_items = _sorted_key_map(item=_attribute, transform=_transform_string_value)

        for key, value, _original_key in sorted_items:
            serialized_attribute.write(_serialize_string(key))
            serialized_attribute.write(serialize_attribute(value))

        return serialized_attribute.getvalue()
Пример #5
0
    def _serialize_set(tag, _attribute, member_function):
        # type: (Tag, dynamodb_types.SET[dynamodb_types.ATTRIBUTE], Callable) -> bytes
        """
        :param bytes tag: Tag to identify this set
        :param set _attribute: Attribute to serialize
        :param member_function: Serialization function for members
        :returns: Serialized _attribute
        :rtype: bytes
        """
        serialized_attribute = io.BytesIO()
        serialized_attribute.write(_RESERVED)
        serialized_attribute.write(tag.tag)
        serialized_attribute.write(encode_length(_attribute))

        encoded_members = []
        for member in _attribute:
            encoded_members.append(member_function(member))
        for member in sorted(encoded_members):
            serialized_attribute.write(encode_value(member))

        return serialized_attribute.getvalue()