# 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 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
# 
# Path: rlp/atomic.py
# class Atomic(metaclass=abc.ABCMeta):
#     """ABC for objects that can be RLP encoded as is."""
#     pass


from rlp.exceptions import SerializationError, DeserializationError
from rlp.atomic import Atomic
    :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)):

# 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 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
# 
# Path: rlp/atomic.py
# class Atomic(metaclass=abc.ABCMeta):
#     """ABC for objects that can be RLP encoded as is."""
#     pass


# Path: rlp/sedes/binary.py
from rlp.exceptions import SerializationError, DeserializationError
from rlp.atomic import Atomic

    :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)