"""Preconfigured converters for msgpack."""fromdatetimeimportdatetime,timezonefromtypingimportAny,Type,TypeVarfrommsgpackimportdumps,loadsfromcattrs._compatimportAbstractSetfrom..convertersimportBaseConverter,ConverterT=TypeVar("T")
[docs]defconfigure_converter(converter:BaseConverter):""" Configure the converter for use with the msgpack library. * datetimes are serialized as timestamp floats * sets are serialized as lists """converter.register_unstructure_hook(datetime,lambdav:v.timestamp())converter.register_structure_hook(datetime,lambdav,_:datetime.fromtimestamp(v,timezone.utc))