# Path: rlp/codec.py
# def encode(obj, sedes=None, infer_serializer=True, cache=True):
#     """Encode a Python object in RLP format.
# 
#     By default, the object is serialized in a suitable way first (using
#     :func:`rlp.infer_sedes`) and then encoded. Serialization can be explicitly
#     suppressed by setting `infer_serializer` to ``False`` and not passing an
#     alternative as `sedes`.
# 
#     If `obj` has an attribute :attr:`_cached_rlp` (as, notably,
#     :class:`rlp.Serializable`) and its value is not `None`, this value is
#     returned bypassing serialization and encoding, unless `sedes` is given (as
#     the cache is assumed to refer to the standard serialization which can be
#     replaced by specifying `sedes`).
# 
#     If `obj` is a :class:`rlp.Serializable` and `cache` is true, the result of
#     the encoding will be stored in :attr:`_cached_rlp` if it is empty.
# 
#     :param sedes: an object implementing a function ``serialize(obj)`` which will be used to
#                   serialize ``obj`` before encoding, or ``None`` to use the infered one (if any)
#     :param infer_serializer: if ``True`` an appropriate serializer will be selected using
#                              :func:`rlp.infer_sedes` to serialize `obj` before encoding
#     :param cache: cache the return value in `obj._cached_rlp` if possible
#                   (default `True`)
#     :returns: the RLP encoded item
#     :raises: :exc:`rlp.EncodingError` in the rather unlikely case that the item is too big to
#              encode (will not happen)
#     :raises: :exc:`rlp.SerializationError` if the serialization fails
#     """
#     if isinstance(obj, Serializable):
#         cached_rlp = obj._cached_rlp
#         if sedes is None and cached_rlp:
#             return cached_rlp
#         else:
#             really_cache = (
#                 cache and
#                 sedes is None
#             )
#     else:
#         really_cache = False
# 
#     if sedes:
#         item = sedes.serialize(obj)
#     elif infer_serializer:
#         item = infer_sedes(obj).serialize(obj)
#     else:
#         item = obj
# 
#     result = encode_raw(item)
#     if really_cache:
#         obj._cached_rlp = result
#     return result
# 
# def decode(rlp, sedes=None, strict=True, recursive_cache=False, **kwargs):
#     """Decode an RLP encoded object.
# 
#     If the deserialized result `obj` has an attribute :attr:`_cached_rlp` (e.g. if `sedes` is a
#     subclass of :class:`rlp.Serializable`) it will be set to `rlp`, which will improve performance
#     on subsequent :func:`rlp.encode` calls. Bear in mind however that `obj` needs to make sure that
#     this value is updated whenever one of its fields changes or prevent such changes entirely
#     (:class:`rlp.sedes.Serializable` does the latter).
# 
#     :param sedes: an object implementing a function ``deserialize(code)`` which will be applied
#                   after decoding, or ``None`` if no deserialization should be performed
#     :param \*\*kwargs: additional keyword arguments that will be passed to the deserializer
#     :param strict: if false inputs that are longer than necessary don't cause an exception
#     :returns: the decoded and maybe deserialized Python object
#     :raises: :exc:`rlp.DecodingError` if the input string does not end after the root item and
#              `strict` is true
#     :raises: :exc:`rlp.DeserializationError` if the deserialization fails
#     """
#     if not is_bytes(rlp):
#         raise DecodingError('Can only decode RLP bytes, got type %s' % type(rlp).__name__, rlp)
# 
#     item, per_item_rlp = decode_raw(rlp, strict, recursive_cache)
# 
#     if len(per_item_rlp) == 0:
#         per_item_rlp = [rlp]
# 
#     if sedes:
#         obj = sedes.deserialize(item, **kwargs)
#         if is_sequence(obj) or hasattr(obj, '_cached_rlp'):
#             _apply_rlp_cache(obj, per_item_rlp, recursive_cache)
#         return obj
#     else:
#         return item
# 
# Path: rlp/lazy.py
# def decode_lazy(rlp, sedes=None, **sedes_kwargs):
#     """Decode an RLP encoded object in a lazy fashion.
# 
#     If the encoded object is a bytestring, this function acts similar to
#     :func:`rlp.decode`. If it is a list however, a :class:`LazyList` is
#     returned instead. This object will decode the string lazily, avoiding
#     both horizontal and vertical traversing as much as possible.
# 
#     The way `sedes` is applied depends on the decoded object: If it is a string
#     `sedes` deserializes it as a whole; if it is a list, each element is
#     deserialized individually. In both cases, `sedes_kwargs` are passed on.
#     Note that, if a deserializer is used, only "horizontal" but not
#     "vertical lazyness" can be preserved.
# 
#     :param rlp: the RLP string to decode
#     :param sedes: an object implementing a method ``deserialize(code)`` which
#                   is used as described above, or ``None`` if no
#                   deserialization should be performed
#     :param \*\*sedes_kwargs: additional keyword arguments that will be passed
#                              to the deserializers
#     :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


from rlp import (
    encode,
    decode,
    decode_lazy,
)
# -*- coding: utf8 -*-


def test_bytearray():
    e = encode(b'abc')
    expected = decode(e)
    actual = decode(bytearray(e))
    assert actual == expected


def test_bytearray_lazy():
    e = encode(b'abc')

# Path: rlp/codec.py
# def encode(obj, sedes=None, infer_serializer=True, cache=True):
#     """Encode a Python object in RLP format.
# 
#     By default, the object is serialized in a suitable way first (using
#     :func:`rlp.infer_sedes`) and then encoded. Serialization can be explicitly
#     suppressed by setting `infer_serializer` to ``False`` and not passing an
#     alternative as `sedes`.
# 
#     If `obj` has an attribute :attr:`_cached_rlp` (as, notably,
#     :class:`rlp.Serializable`) and its value is not `None`, this value is
#     returned bypassing serialization and encoding, unless `sedes` is given (as
#     the cache is assumed to refer to the standard serialization which can be
#     replaced by specifying `sedes`).
# 
#     If `obj` is a :class:`rlp.Serializable` and `cache` is true, the result of
#     the encoding will be stored in :attr:`_cached_rlp` if it is empty.
# 
#     :param sedes: an object implementing a function ``serialize(obj)`` which will be used to
#                   serialize ``obj`` before encoding, or ``None`` to use the infered one (if any)
#     :param infer_serializer: if ``True`` an appropriate serializer will be selected using
#                              :func:`rlp.infer_sedes` to serialize `obj` before encoding
#     :param cache: cache the return value in `obj._cached_rlp` if possible
#                   (default `True`)
#     :returns: the RLP encoded item
#     :raises: :exc:`rlp.EncodingError` in the rather unlikely case that the item is too big to
#              encode (will not happen)
#     :raises: :exc:`rlp.SerializationError` if the serialization fails
#     """
#     if isinstance(obj, Serializable):
#         cached_rlp = obj._cached_rlp
#         if sedes is None and cached_rlp:
#             return cached_rlp
#         else:
#             really_cache = (
#                 cache and
#                 sedes is None
#             )
#     else:
#         really_cache = False
# 
#     if sedes:
#         item = sedes.serialize(obj)
#     elif infer_serializer:
#         item = infer_sedes(obj).serialize(obj)
#     else:
#         item = obj
# 
#     result = encode_raw(item)
#     if really_cache:
#         obj._cached_rlp = result
#     return result
# 
# def decode(rlp, sedes=None, strict=True, recursive_cache=False, **kwargs):
#     """Decode an RLP encoded object.
# 
#     If the deserialized result `obj` has an attribute :attr:`_cached_rlp` (e.g. if `sedes` is a
#     subclass of :class:`rlp.Serializable`) it will be set to `rlp`, which will improve performance
#     on subsequent :func:`rlp.encode` calls. Bear in mind however that `obj` needs to make sure that
#     this value is updated whenever one of its fields changes or prevent such changes entirely
#     (:class:`rlp.sedes.Serializable` does the latter).
# 
#     :param sedes: an object implementing a function ``deserialize(code)`` which will be applied
#                   after decoding, or ``None`` if no deserialization should be performed
#     :param \*\*kwargs: additional keyword arguments that will be passed to the deserializer
#     :param strict: if false inputs that are longer than necessary don't cause an exception
#     :returns: the decoded and maybe deserialized Python object
#     :raises: :exc:`rlp.DecodingError` if the input string does not end after the root item and
#              `strict` is true
#     :raises: :exc:`rlp.DeserializationError` if the deserialization fails
#     """
#     if not is_bytes(rlp):
#         raise DecodingError('Can only decode RLP bytes, got type %s' % type(rlp).__name__, rlp)
# 
#     item, per_item_rlp = decode_raw(rlp, strict, recursive_cache)
# 
#     if len(per_item_rlp) == 0:
#         per_item_rlp = [rlp]
# 
#     if sedes:
#         obj = sedes.deserialize(item, **kwargs)
#         if is_sequence(obj) or hasattr(obj, '_cached_rlp'):
#             _apply_rlp_cache(obj, per_item_rlp, recursive_cache)
#         return obj
#     else:
#         return item
# 
# Path: rlp/lazy.py
# def decode_lazy(rlp, sedes=None, **sedes_kwargs):
#     """Decode an RLP encoded object in a lazy fashion.
# 
#     If the encoded object is a bytestring, this function acts similar to
#     :func:`rlp.decode`. If it is a list however, a :class:`LazyList` is
#     returned instead. This object will decode the string lazily, avoiding
#     both horizontal and vertical traversing as much as possible.
# 
#     The way `sedes` is applied depends on the decoded object: If it is a string
#     `sedes` deserializes it as a whole; if it is a list, each element is
#     deserialized individually. In both cases, `sedes_kwargs` are passed on.
#     Note that, if a deserializer is used, only "horizontal" but not
#     "vertical lazyness" can be preserved.
# 
#     :param rlp: the RLP string to decode
#     :param sedes: an object implementing a method ``deserialize(code)`` which
#                   is used as described above, or ``None`` if no
#                   deserialization should be performed
#     :param \*\*sedes_kwargs: additional keyword arguments that will be passed
#                              to the deserializers
#     :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


# Path: tests/test_bytearray.py
from rlp import (
    encode,
    decode,
    decode_lazy,
)

# -*- coding: utf8 -*-


def test_bytearray():
    e = encode(b'abc')
    expected = decode(e)
    actual = decode(bytearray(e))
    assert actual == expected


def test_bytearray_lazy():
    e = encode(b'abc')

    expected = decode(e)