# Path: rlp/codec.py
# def consume_length_prefix(rlp, start):
#     """Read a length prefix from an RLP string.
# 
#     :param rlp: the rlp byte string to read from
#     :param start: the position at which to start reading
#     :returns: a tuple ``(prefix, type, length, end)``, where ``type`` is either ``str``
#               or ``list`` depending on the type of the following payload,
#               ``length`` is the length of the payload in bytes, and ``end`` is
#               the position of the first payload byte in the rlp string
#     """
#     b0 = rlp[start]
#     if b0 < 128:  # single byte
#         return (b'', bytes, 1, start)
#     elif b0 < SHORT_STRING:  # short string
#         if b0 - 128 == 1 and rlp[start + 1] < 128:
#             raise DecodingError('Encoded as short string although single byte was possible', rlp)
#         return (rlp[start:start + 1], bytes, b0 - 128, start + 1)
#     elif b0 < 192:  # long string
#         ll = b0 - 183  # - (128 + 56 - 1)
#         if rlp[start + 1:start + 2] == b'\x00':
#             raise DecodingError('Length starts with zero bytes', rlp)
#         len_prefix = rlp[start + 1:start + 1 + ll]
#         l = big_endian_to_int(len_prefix)  # noqa: E741
#         if l < 56:
#             raise DecodingError('Long string prefix used for short string', rlp)
#         return (rlp[start:start + 1] + len_prefix, bytes, l, start + 1 + ll)
#     elif b0 < 192 + 56:  # short list
#         return (rlp[start:start + 1], list, b0 - 192, start + 1)
#     else:  # long list
#         ll = b0 - 192 - 56 + 1
#         if rlp[start + 1:start + 2] == b'\x00':
#             raise DecodingError('Length starts with zero bytes', rlp)
#         len_prefix = rlp[start + 1:start + 1 + ll]
#         l = big_endian_to_int(len_prefix)  # noqa: E741
#         if l < 56:
#             raise DecodingError('Long list prefix used for short list', rlp)
#         return (rlp[start:start + 1] + len_prefix, list, l, start + 1 + ll)
# 
# def consume_payload(rlp, prefix, start, type_, length):
#     """Read the payload of an item from an RLP string.
# 
#     :param rlp: the rlp string to read from
#     :param type_: the type of the payload (``bytes`` or ``list``)
#     :param start: the position at which to start reading
#     :param length: the length of the payload in bytes
#     :returns: a tuple ``(item, per_item_rlp, end)``, where ``item`` is
#               the read item, per_item_rlp is a list containing the RLP
#               encoding of each item and ``end`` is the position of the
#               first unprocessed byte
#     """
#     if type_ is bytes:
#         item = rlp[start: start + length]
#         return (item, [prefix + item], start + length)
#     elif type_ is list:
#         items = []
#         per_item_rlp = []
#         list_rlp = prefix
#         next_item_start = start
#         end = next_item_start + length
#         while next_item_start < end:
#             p, t, l, s = consume_length_prefix(rlp, next_item_start)
#             item, item_rlp, next_item_start = consume_payload(rlp, p, s, t, l)
#             per_item_rlp.append(item_rlp)
#             # When the item returned above is a single element, item_rlp will also contain a
#             # single element, but when it's a list, the first element will be the RLP of the
#             # whole List, which is what we want here.
#             list_rlp += item_rlp[0]
#             items.append(item)
#         per_item_rlp.insert(0, list_rlp)
#         if next_item_start > end:
#             raise DecodingError('List length prefix announced a too small '
#                                 'length', rlp)
#         return (items, per_item_rlp, next_item_start)
#     else:
#         raise TypeError('Type must be either list or bytes')
# 
# Path: rlp/exceptions.py
# class DecodingError(RLPException):
#     """Exception raised if decoding fails.
# 
#     :ivar rlp: the RLP string that could not be decoded
#     """
# 
#     def __init__(self, message, rlp):
#         super(DecodingError, self).__init__(message)
#         self.rlp = rlp
# 
# Path: rlp/atomic.py
# class Atomic(metaclass=abc.ABCMeta):
#     """ABC for objects that can be RLP encoded as is."""
#     pass


from collections.abc import Iterable, Sequence
from .codec import consume_length_prefix, consume_payload
from .exceptions import DecodingError
from .atomic import Atomic
    :returns: either the already decoded and deserialized object (if encoded as
              a string) or an instance of :class:`rlp.LazyList`
    """
    item, end = consume_item_lazy(rlp, 0)
    if end != len(rlp):
        raise DecodingError('RLP length prefix announced wrong length', rlp)
    if isinstance(item, LazyList):
        item.sedes = sedes
        item.sedes_kwargs = sedes_kwargs
        return item
    elif sedes:
        return sedes.deserialize(item, **sedes_kwargs)
    else:
        return item


def consume_item_lazy(rlp, start):
    """Read an item from an RLP string lazily.

    If the length prefix announces a string, the string is read; if it
    announces a list, a :class:`LazyList` is created.

    :param rlp: the rlp string to read from
    :param start: the position at which to start reading
    :returns: a tuple ``(item, end)`` where ``item`` is the read string or a
              :class:`LazyList` and ``end`` is the position of the first
              unprocessed byte.
    """
    p, t, l, s = consume_length_prefix(rlp, start)
    if t is bytes:

# Path: rlp/codec.py
# def consume_length_prefix(rlp, start):
#     """Read a length prefix from an RLP string.
# 
#     :param rlp: the rlp byte string to read from
#     :param start: the position at which to start reading
#     :returns: a tuple ``(prefix, type, length, end)``, where ``type`` is either ``str``
#               or ``list`` depending on the type of the following payload,
#               ``length`` is the length of the payload in bytes, and ``end`` is
#               the position of the first payload byte in the rlp string
#     """
#     b0 = rlp[start]
#     if b0 < 128:  # single byte
#         return (b'', bytes, 1, start)
#     elif b0 < SHORT_STRING:  # short string
#         if b0 - 128 == 1 and rlp[start + 1] < 128:
#             raise DecodingError('Encoded as short string although single byte was possible', rlp)
#         return (rlp[start:start + 1], bytes, b0 - 128, start + 1)
#     elif b0 < 192:  # long string
#         ll = b0 - 183  # - (128 + 56 - 1)
#         if rlp[start + 1:start + 2] == b'\x00':
#             raise DecodingError('Length starts with zero bytes', rlp)
#         len_prefix = rlp[start + 1:start + 1 + ll]
#         l = big_endian_to_int(len_prefix)  # noqa: E741
#         if l < 56:
#             raise DecodingError('Long string prefix used for short string', rlp)
#         return (rlp[start:start + 1] + len_prefix, bytes, l, start + 1 + ll)
#     elif b0 < 192 + 56:  # short list
#         return (rlp[start:start + 1], list, b0 - 192, start + 1)
#     else:  # long list
#         ll = b0 - 192 - 56 + 1
#         if rlp[start + 1:start + 2] == b'\x00':
#             raise DecodingError('Length starts with zero bytes', rlp)
#         len_prefix = rlp[start + 1:start + 1 + ll]
#         l = big_endian_to_int(len_prefix)  # noqa: E741
#         if l < 56:
#             raise DecodingError('Long list prefix used for short list', rlp)
#         return (rlp[start:start + 1] + len_prefix, list, l, start + 1 + ll)
# 
# def consume_payload(rlp, prefix, start, type_, length):
#     """Read the payload of an item from an RLP string.
# 
#     :param rlp: the rlp string to read from
#     :param type_: the type of the payload (``bytes`` or ``list``)
#     :param start: the position at which to start reading
#     :param length: the length of the payload in bytes
#     :returns: a tuple ``(item, per_item_rlp, end)``, where ``item`` is
#               the read item, per_item_rlp is a list containing the RLP
#               encoding of each item and ``end`` is the position of the
#               first unprocessed byte
#     """
#     if type_ is bytes:
#         item = rlp[start: start + length]
#         return (item, [prefix + item], start + length)
#     elif type_ is list:
#         items = []
#         per_item_rlp = []
#         list_rlp = prefix
#         next_item_start = start
#         end = next_item_start + length
#         while next_item_start < end:
#             p, t, l, s = consume_length_prefix(rlp, next_item_start)
#             item, item_rlp, next_item_start = consume_payload(rlp, p, s, t, l)
#             per_item_rlp.append(item_rlp)
#             # When the item returned above is a single element, item_rlp will also contain a
#             # single element, but when it's a list, the first element will be the RLP of the
#             # whole List, which is what we want here.
#             list_rlp += item_rlp[0]
#             items.append(item)
#         per_item_rlp.insert(0, list_rlp)
#         if next_item_start > end:
#             raise DecodingError('List length prefix announced a too small '
#                                 'length', rlp)
#         return (items, per_item_rlp, next_item_start)
#     else:
#         raise TypeError('Type must be either list or bytes')
# 
# Path: rlp/exceptions.py
# class DecodingError(RLPException):
#     """Exception raised if decoding fails.
# 
#     :ivar rlp: the RLP string that could not be decoded
#     """
# 
#     def __init__(self, message, rlp):
#         super(DecodingError, self).__init__(message)
#         self.rlp = rlp
# 
# Path: rlp/atomic.py
# class Atomic(metaclass=abc.ABCMeta):
#     """ABC for objects that can be RLP encoded as is."""
#     pass


# Path: rlp/lazy.py
from collections.abc import Iterable, Sequence
from .codec import consume_length_prefix, consume_payload
from .exceptions import DecodingError
from .atomic import Atomic

    :returns: either the already decoded and deserialized object (if encoded as
              a string) or an instance of :class:`rlp.LazyList`
    """
    item, end = consume_item_lazy(rlp, 0)
    if end != len(rlp):
        raise DecodingError('RLP length prefix announced wrong length', rlp)
    if isinstance(item, LazyList):
        item.sedes = sedes
        item.sedes_kwargs = sedes_kwargs
        return item
    elif sedes:
        return sedes.deserialize(item, **sedes_kwargs)
    else:
        return item


def consume_item_lazy(rlp, start):
    """Read an item from an RLP string lazily.

    If the length prefix announces a string, the string is read; if it
    announces a list, a :class:`LazyList` is created.

    :param rlp: the rlp string to read from
    :param start: the position at which to start reading
    :returns: a tuple ``(item, end)`` where ``item`` is the read string or a
              :class:`LazyList` and ``end`` is the position of the first
              unprocessed byte.
    """
    p, t, l, s = consume_length_prefix(rlp, start)
    if t is bytes:

        item, _, end = consume_payload(rlp, p, s, bytes, l)