예제 #1
0
def default_time_serializer(obj: date, **kwargs) -> str:
    """
    Serialize the given time instance to a string. It uses the RFC3339
    pattern.
    :param obj: the time instance that is to be serialized.
    :param kwargs: not used.
    :return: ``time`` as an RFC3339 string.
    """
    return to_str(obj, False, kwargs['fork_inst'], RFC3339_TIME_PATTERN)
예제 #2
0
def default_date_serializer(obj: date, **kwargs) -> str:
    """
    Serialize the given date instance to a string. It uses the RFC3339
    pattern. If date is a localtime, an offset is provided. If date is
    in UTC, the result is suffixed with a 'Z'.
    :param obj: the date instance that is to be serialized.
    :param kwargs: not used.
    :return: ``date`` as an RFC3339 string.
    """
    return to_str(obj, False, kwargs['fork_inst'], RFC3339_DATE_PATTERN)
예제 #3
0
def default_datetime_serializer(obj: datetime,
                                strip_microseconds: Optional[bool] = True,
                                **kwargs) -> str:
    """
    Serialize the given datetime instance to a string. It uses the RFC3339
    pattern. If datetime is a localtime, an offset is provided. If datetime is
    in UTC, the result is suffixed with a 'Z'.
    :param obj: the datetime instance that is to be serialized.
    :param strip_microseconds: determines whether microseconds should be
    omitted.
    :param kwargs: not used.
    :return: ``datetime`` as an RFC3339 string.
    """
    return to_str(obj, strip_microseconds, kwargs['fork_inst'],
                  RFC3339_DATETIME_PATTERN)
예제 #4
0
def _get_dict_with_meta(obj: dict, cls_name: str, verbose: Verbosity,
                        fork_inst: type) -> dict:
    # This function will add a -meta section to the given obj (provided that
    # the given obj has -cls attributes for all children).
    if verbose is Verbosity.WITH_NOTHING:
        return obj

    obj[META_ATTR] = {}
    if Verbosity.WITH_CLASS_INFO in verbose:
        collection_of_types = {}
        _fill_collection_of_types(obj, cls_name, '/', collection_of_types)
        collection_of_types['/'] = cls_name
        obj[META_ATTR]['classes'] = collection_of_types
    if Verbosity.WITH_DUMP_TIME in verbose:
        dump_time = to_str(datetime.now(tz=timezone.utc), True, fork_inst)
        obj[META_ATTR]['dump_time'] = dump_time
    return obj