commonpower.benchmark.benchmark.TimedeltaHandler

class TimedeltaHandler(context)[source]

Bases: BaseHandler

A custom handler for serializing and deserializing timedelta objects to and from JSON.

This handler is used by the jsonpickle library to handle serialization and deserialization of timedelta objects.

None
flatten(obj, data)[source]

Flattens the timedelta object into a dictionary representation.

restore(obj)[source]

Restores the object from a dictionary representation.

Usage:

This handler should be registered with the jsonpickle library to enable serialization and deserialization of timedelta objects.

Initialize a new handler to handle a registered type.

Parameters:
  • context: reference to pickler/unpickler

Methods

flatten

Flatten obj into a json-friendly form and write result to data.

handles

Register this handler for the given class. Suitable as a decorator, e.g.::.

restore

Restore an object of the registered type from the json-friendly representation obj and return it.

flatten(obj, data: dict)[source]

Flatten obj into a json-friendly form and write result to data.

Parameters:
  • obj (object) – The object to be serialized.

  • data (dict) – A partially filled dictionary which will contain the json-friendly representation of obj once this method has finished.

restore(obj)[source]

Restore an object of the registered type from the json-friendly representation obj and return it.