Example #1
0
def encode(serializer, o):
    if is_iterable(o):
        return serializer.serialize_iterable(map(serializer.encode, o),
                                             length=safe_len(o))
    if serializer.allow_external_objects:
        return serializer.serialize_external_object(o)

    raise NotImplementedError('Cannot serialize object of class %s' %
                              o.__class__)
Example #2
0
def get_length(iterable, length=None):
    if length is not None:
        return iterable, length

    length = safe_len(iterable)

    if length is not None:
        return iterable, length

    iterable = tuple(iterable)

    return iterable, len(iterable)
Example #3
0
def _to_key_value(func, serializer, o):
    return func(((serializer.encode(key), serializer.encode(value))
                 for key, value in o.items()),
                length=safe_len(o))
Example #4
0
def encode_iter(serializer, o):
    return serializer.serialize_iterable(map(serializer.encode, o),
                                         length=safe_len(o))