def pack(content, *args, default=convert.msgpack, **kwargs): # type: ignore """Msgpacks with preconversion for common unserializable types in place""" if isinstance(content, tuple): content = convert_namedtuple(content) return msgpack.pack(content, default=default, *args, **kwargs)
def dumps(content, *args, default=convert.json, **kwargs): # type: ignore """JSON dumps with preconversion for common unserializable types in place""" if isinstance(content, tuple): content = convert_namedtuple(content) return json.dumps(content, default=default, *args, **kwargs)
def dumps(content, *args, on_unknown=convert.bson, **kwargs): # type: ignore """BSON dumps with preconversion for common unserializable types in place""" if isinstance(content, tuple): content = convert_namedtuple(content) return bson.dumps(content, on_unknown=on_unknown, *args, **kwargs)