# Path: rlp/exceptions.py
# class SerializationError(RLPException):
#     """Exception raised if serialization fails.
# 
#     :ivar obj: the object that could not be serialized
#     """
# 
#     def __init__(self, message, obj):
#         super(SerializationError, self).__init__(message)
#         self.obj = obj
# 
# class ListSerializationError(SerializationError):
#     """Exception raised if serialization by a :class:`sedes.List` fails.
# 
#     :ivar element_exception: the exception that occurred during the serialization of one of the
#                              elements, or `None` if the error is unrelated to a specific element
#     :ivar index: the index in the list that produced the error or `None` if the error is unrelated
#                  to a specific element
#     """
# 
#     def __init__(self, message=None, obj=None, element_exception=None, index=None):
#         if message is None:
#             assert index is not None
#             assert element_exception is not None
#             message = ('Serialization failed because of element at index {} '
#                        '("{}")'.format(index, str(element_exception)))
#         super(ListSerializationError, self).__init__(message, obj)
#         self.index = index
#         self.element_exception = element_exception
# 
# class DeserializationError(RLPException):
#     """Exception raised if deserialization fails.
# 
#     :ivar serial: the decoded RLP string that could not be deserialized
#     """
# 
#     def __init__(self, message, serial):
#         super(DeserializationError, self).__init__(message)
#         self.serial = serial
# 
# class ListDeserializationError(DeserializationError):
#     """Exception raised if deserialization by a :class:`sedes.List` fails.
# 
#     :ivar element_exception: the exception that occurred during the deserialization of one of the
#                              elements, or `None` if the error is unrelated to a specific element
#     :ivar index: the index in the list that produced the error or `None` if the error is unrelated
#                  to a specific element
#     """
# 
#     def __init__(self, message=None, serial=None, element_exception=None, index=None):
#         if not message:
#             assert index is not None
#             assert element_exception is not None
#             message = ('Deserialization failed because of element at index {} '
#                        '("{}")'.format(index, str(element_exception)))
#         super(ListDeserializationError, self).__init__(message, serial)
#         self.index = index
#         self.element_exception = element_exception
# 
# Path: rlp/sedes/binary.py
# class Binary(object):
#     """A sedes object for binary data of certain length.
# 
#     :param min_length: the minimal length in bytes or `None` for no lower limit
#     :param max_length: the maximal length in bytes or `None` for no upper limit
#     :param allow_empty: if true, empty strings are considered valid even if
#                         a minimum length is required otherwise
#     """
# 
#     def __init__(self, min_length=None, max_length=None, allow_empty=False):
#         self.min_length = min_length or 0
#         if max_length is None:
#             self.max_length = float('inf')
#         else:
#             self.max_length = max_length
#         self.allow_empty = allow_empty
# 
#     @classmethod
#     def fixed_length(cls, l, allow_empty=False):
#         """Create a sedes for binary data with exactly `l` bytes."""
#         return cls(l, l, allow_empty=allow_empty)
# 
#     @classmethod
#     def is_valid_type(cls, obj):
#         return isinstance(obj, (bytes, bytearray))
# 
#     def is_valid_length(self, l):
#         return any((self.min_length <= l <= self.max_length,
#                     self.allow_empty and l == 0))
# 
#     def serialize(self, obj):
#         if not Binary.is_valid_type(obj):
#             raise SerializationError('Object is not a serializable ({})'.format(type(obj)), obj)
# 
#         if not self.is_valid_length(len(obj)):
#             raise SerializationError('Object has invalid length', obj)
# 
#         return obj
# 
#     def deserialize(self, serial):
#         if not isinstance(serial, Atomic):
#             m = 'Objects of type {} cannot be deserialized'
#             raise DeserializationError(m.format(type(serial).__name__), serial)
# 
#         if self.is_valid_length(len(serial)):
#             return serial
#         else:
#             raise DeserializationError('{} has invalid length'.format(type(serial)), serial)


from collections.abc import Sequence
from eth_utils import (
    to_list,
    to_tuple,
)
from rlp.exceptions import (
    SerializationError,
    ListSerializationError,
    DeserializationError,
    ListDeserializationError,
)
from .binary import (
    Binary as BinaryClass,
)
            raise ListSerializationError('Can only serialize sequences', obj)

        if self.max_length is not None and len(obj) > self.max_length:
            raise ListSerializationError(
                'Too many elements ({}, allowed {})'.format(
                    len(obj),
                    self.max_length,
                ),
                obj=obj,
            )

        for index, element in enumerate(obj):
            try:
                yield self.element_sedes.serialize(element)
            except SerializationError as e:
                raise ListSerializationError(obj=obj, element_exception=e, index=index)

    @to_tuple
    def deserialize(self, serial):
        if not is_sequence(serial):
            raise ListDeserializationError('Can only deserialize sequences', serial=serial)
        for index, element in enumerate(serial):
            if self.max_length is not None and index >= self.max_length:
                raise ListDeserializationError(
                    'Too many elements (more than {})'.format(self.max_length),
                    serial=serial,
                )

            try:
                yield self.element_sedes.deserialize(element)

# Path: rlp/exceptions.py
# class SerializationError(RLPException):
#     """Exception raised if serialization fails.
# 
#     :ivar obj: the object that could not be serialized
#     """
# 
#     def __init__(self, message, obj):
#         super(SerializationError, self).__init__(message)
#         self.obj = obj
# 
# class ListSerializationError(SerializationError):
#     """Exception raised if serialization by a :class:`sedes.List` fails.
# 
#     :ivar element_exception: the exception that occurred during the serialization of one of the
#                              elements, or `None` if the error is unrelated to a specific element
#     :ivar index: the index in the list that produced the error or `None` if the error is unrelated
#                  to a specific element
#     """
# 
#     def __init__(self, message=None, obj=None, element_exception=None, index=None):
#         if message is None:
#             assert index is not None
#             assert element_exception is not None
#             message = ('Serialization failed because of element at index {} '
#                        '("{}")'.format(index, str(element_exception)))
#         super(ListSerializationError, self).__init__(message, obj)
#         self.index = index
#         self.element_exception = element_exception
# 
# class DeserializationError(RLPException):
#     """Exception raised if deserialization fails.
# 
#     :ivar serial: the decoded RLP string that could not be deserialized
#     """
# 
#     def __init__(self, message, serial):
#         super(DeserializationError, self).__init__(message)
#         self.serial = serial
# 
# class ListDeserializationError(DeserializationError):
#     """Exception raised if deserialization by a :class:`sedes.List` fails.
# 
#     :ivar element_exception: the exception that occurred during the deserialization of one of the
#                              elements, or `None` if the error is unrelated to a specific element
#     :ivar index: the index in the list that produced the error or `None` if the error is unrelated
#                  to a specific element
#     """
# 
#     def __init__(self, message=None, serial=None, element_exception=None, index=None):
#         if not message:
#             assert index is not None
#             assert element_exception is not None
#             message = ('Deserialization failed because of element at index {} '
#                        '("{}")'.format(index, str(element_exception)))
#         super(ListDeserializationError, self).__init__(message, serial)
#         self.index = index
#         self.element_exception = element_exception
# 
# Path: rlp/sedes/binary.py
# class Binary(object):
#     """A sedes object for binary data of certain length.
# 
#     :param min_length: the minimal length in bytes or `None` for no lower limit
#     :param max_length: the maximal length in bytes or `None` for no upper limit
#     :param allow_empty: if true, empty strings are considered valid even if
#                         a minimum length is required otherwise
#     """
# 
#     def __init__(self, min_length=None, max_length=None, allow_empty=False):
#         self.min_length = min_length or 0
#         if max_length is None:
#             self.max_length = float('inf')
#         else:
#             self.max_length = max_length
#         self.allow_empty = allow_empty
# 
#     @classmethod
#     def fixed_length(cls, l, allow_empty=False):
#         """Create a sedes for binary data with exactly `l` bytes."""
#         return cls(l, l, allow_empty=allow_empty)
# 
#     @classmethod
#     def is_valid_type(cls, obj):
#         return isinstance(obj, (bytes, bytearray))
# 
#     def is_valid_length(self, l):
#         return any((self.min_length <= l <= self.max_length,
#                     self.allow_empty and l == 0))
# 
#     def serialize(self, obj):
#         if not Binary.is_valid_type(obj):
#             raise SerializationError('Object is not a serializable ({})'.format(type(obj)), obj)
# 
#         if not self.is_valid_length(len(obj)):
#             raise SerializationError('Object has invalid length', obj)
# 
#         return obj
# 
#     def deserialize(self, serial):
#         if not isinstance(serial, Atomic):
#             m = 'Objects of type {} cannot be deserialized'
#             raise DeserializationError(m.format(type(serial).__name__), serial)
# 
#         if self.is_valid_length(len(serial)):
#             return serial
#         else:
#             raise DeserializationError('{} has invalid length'.format(type(serial)), serial)


# Path: rlp/sedes/lists.py
from collections.abc import Sequence
from eth_utils import (
    to_list,
    to_tuple,
)
from rlp.exceptions import (
    SerializationError,
    ListSerializationError,
    DeserializationError,
    ListDeserializationError,
)
from .binary import (
    Binary as BinaryClass,
)

            raise ListSerializationError('Can only serialize sequences', obj)

        if self.max_length is not None and len(obj) > self.max_length:
            raise ListSerializationError(
                'Too many elements ({}, allowed {})'.format(
                    len(obj),
                    self.max_length,
                ),
                obj=obj,
            )

        for index, element in enumerate(obj):
            try:
                yield self.element_sedes.serialize(element)
            except SerializationError as e:
                raise ListSerializationError(obj=obj, element_exception=e, index=index)

    @to_tuple
    def deserialize(self, serial):
        if not is_sequence(serial):
            raise ListDeserializationError('Can only deserialize sequences', serial=serial)
        for index, element in enumerate(serial):
            if self.max_length is not None and index >= self.max_length:
                raise ListDeserializationError(
                    'Too many elements (more than {})'.format(self.max_length),
                    serial=serial,
                )

            try:
                yield self.element_sedes.deserialize(element)

            except DeserializationError as e: