示例#1
0
def encode_timetable(var: Timetable) -> Dict[str, Any]:
    """Encode a timetable instance.

    This delegates most of the serialization work to the type, so the behavior
    can be completely controlled by a custom subclass.
    """
    return {"type": as_importable_string(type(var)), "value": var.serialize()}
示例#2
0
def _encode_timetable(var: Timetable) -> Dict[str, Any]:
    """Encode a timetable instance.

    This delegates most of the serialization work to the type, so the behavior
    can be completely controlled by a custom subclass.
    """
    timetable_class = type(var)
    importable_string = as_importable_string(timetable_class)
    if _get_registered_timetable(importable_string) is None:
        raise _TimetableNotRegistered(importable_string)
    return {Encoding.TYPE: importable_string, Encoding.VAR: var.serialize()}