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__)
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)
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))
def encode_iter(serializer, o): return serializer.serialize_iterable(map(serializer.encode, o), length=safe_len(o))