# Path: rlp/sedes/big_endian_int.py
# class BigEndianInt(object):
#     def __init__(self, l=None):
#     def serialize(self, obj):
#     def deserialize(self, serial):
# 
# Path: rlp/sedes/lists.py
# class CountableList(object):
# 
#     """A sedes for lists of arbitrary length.
# 
#     :param element_sedes: when (de-)serializing a list, this sedes will be
#                           applied to all of its elements
#     :param max_length: maximum number of allowed elements, or `None` for no limit
#     """
# 
#     def __init__(self, element_sedes, max_length=None):
#         self.element_sedes = element_sedes
#         self.max_length = max_length
# 
#     @to_list
#     def serialize(self, obj):
#         if not is_sequence(obj):
#             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:
#                 raise ListDeserializationError(serial=serial, element_exception=e, index=index)
# 
# 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


import pytest
import rlp
from rlp.sedes import big_endian_int
from rlp.sedes.lists import CountableList
from rlp import SerializationError, DeserializationError


def test_countable_list():
    l1 = CountableList(big_endian_int)
    serializable = [(), (1, 2), tuple(range(500))]
    for s in serializable:
        r = l1.serialize(s)
        assert l1.deserialize(r) == s
    not_serializable = ([1, 'asdf'], ['asdf'], [1, [2]], [[]])
    for n in not_serializable:
        with pytest.raises(SerializationError):
            l1.serialize(n)

    l2 = CountableList(CountableList(big_endian_int))
    serializable = ((), ((),), ((1, 2, 3), (4,)), ((5,), (6, 7, 8)), ((), (),
                    (9, 0)))
    for s in serializable:
        r = l2.serialize(s)
        assert l2.deserialize(r) == s
    not_serializable = ([[[]]], [1, 2], [1, ['asdf'], ['fdsa']])
    for n in not_serializable:
        with pytest.raises(SerializationError):
            l2.serialize(n)


# Path: rlp/sedes/big_endian_int.py
# class BigEndianInt(object):
#     def __init__(self, l=None):
#     def serialize(self, obj):
#     def deserialize(self, serial):
# 
# Path: rlp/sedes/lists.py
# class CountableList(object):
# 
#     """A sedes for lists of arbitrary length.
# 
#     :param element_sedes: when (de-)serializing a list, this sedes will be
#                           applied to all of its elements
#     :param max_length: maximum number of allowed elements, or `None` for no limit
#     """
# 
#     def __init__(self, element_sedes, max_length=None):
#         self.element_sedes = element_sedes
#         self.max_length = max_length
# 
#     @to_list
#     def serialize(self, obj):
#         if not is_sequence(obj):
#             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:
#                 raise ListDeserializationError(serial=serial, element_exception=e, index=index)
# 
# 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: tests/test_countablelist.py
import pytest
import rlp
from rlp.sedes import big_endian_int
from rlp.sedes.lists import CountableList
from rlp import SerializationError, DeserializationError



def test_countable_list():
    l1 = CountableList(big_endian_int)
    serializable = [(), (1, 2), tuple(range(500))]
    for s in serializable:
        r = l1.serialize(s)
        assert l1.deserialize(r) == s
    not_serializable = ([1, 'asdf'], ['asdf'], [1, [2]], [[]])
    for n in not_serializable:
        with pytest.raises(SerializationError):
            l1.serialize(n)

    l2 = CountableList(CountableList(big_endian_int))
    serializable = ((), ((),), ((1, 2, 3), (4,)), ((5,), (6, 7, 8)), ((), (),
                    (9, 0)))
    for s in serializable:
        r = l2.serialize(s)
        assert l2.deserialize(r) == s
    not_serializable = ([[[]]], [1, 2], [1, ['asdf'], ['fdsa']])
    for n in not_serializable:
        with pytest.raises(SerializationError):
            l2.serialize(n)


    l3 = CountableList(big_endian_int, max_length=3)