def construct_data_response(structure_family, serialization_registry, payload, metadata, request, format=None, specs=None, expires=None):
    request.state.endpoint = 'data'
    if (specs is None):
        specs = []
    default_media_type = DEFAULT_MEDIA_TYPES[structure_family]
    if (format is not None):
        media_types_or_aliases = format.split(',')
        media_types = [serialization_registry.resolve_alias(t) for t in media_types_or_aliases]
    else:
        media_types = [s.lstrip(' ') for s in request.headers.get('Accept', default_media_type).split(',')]
    supported = set()
    for media_type in media_types:
        if (media_type == '*/*'):
            media_type = default_media_type
        for spec in (specs + [structure_family]):
            media_types_for_spec = serialization_registry.media_types(spec)
            if (media_type in media_types_for_spec):
                break
            supported.update(media_types_for_spec)
        else:
            continue
        break
    else:
        raise UnsupportedMediaTypes(f"None of the media types requested by the client are supported. Supported: {', '.join(supported)}. Requested: {', '.join(media_types)}.")
    with record_timing(request.state.metrics, 'tok'):
        etag = tokenize((payload, media_type))
    headers = {'ETag': etag}
    if (expires is not None):
        headers['Expires'] = expires.strftime(HTTP_EXPIRES_HEADER_FORMAT)
    if (request.headers.get('If-None-Match', '') == etag):
        return Response(status_code=304, headers=headers)
    try:
        content = serialization_registry(structure_family, media_type, payload, metadata)
    except UnsupportedShape as err:
        raise UnsupportedMediaTypes(f'The shape of this data {err.args[0]} is incompatible with the requested format ({media_type}). Slice it or choose a different format.')
    except SerializationError:
        raise UnsupportedMediaTypes('This type is supported in general but there was an unknown error packing this specific data.')
    return PatchedResponse(content=content, media_type=media_type, headers=headers)
def construct_data_response(structure_family, serialization_registry, payload, metadata, request, format=None, specs=None, expires=None):
    request.state.endpoint = 'data'
    if (specs is None):
        specs = []
    default_media_type = DEFAULT_MEDIA_TYPES[structure_family]
    if (format is not None):
        media_types_or_aliases = format.split(',')
        media_types = [serialization_registry.resolve_alias(t) for t in media_types_or_aliases]
    else:
        media_types = [s.lstrip(' ') for s in request.headers.get('Accept', default_media_type).split(',')]
    supported = set()
    for media_type in media_types:
        if (media_type == '*/*'):
            media_type = default_media_type
        for spec in (specs + [structure_family]):
            media_types_for_spec = serialization_registry.media_types(spec)
            if (media_type in media_types_for_spec):
                break
            supported.update(media_types_for_spec)
        else:
            continue
        break
    else:
        raise UnsupportedMediaTypes(f"None of the media types requested by the client are supported. Supported: {', '.join(supported)}. Requested: {', '.join(media_types)}.")
    with record_timing(request.state.metrics, 'tok'):
        etag = tokenize((payload, media_type))
    headers = {'ETag': etag}
    if (expires is not None):
        headers['Expires'] = expires.strftime(HTTP_EXPIRES_HEADER_FORMAT)
    if (request.headers.get('If-None-Match', ) == etag):
        return Response(status_code=304, headers=headers)
    try:
        content = serialization_registry(structure_family, media_type, payload, metadata)
    except UnsupportedShape as err:
        raise UnsupportedMediaTypes(f'The shape of this data {err.args[0]} is incompatible with the requested format ({media_type}). Slice it or choose a different format.')
    except SerializationError:
        raise UnsupportedMediaTypes('This type is supported in general but there was an unknown error packing this specific data.')
    return PatchedResponse(content=content, media_type=media_type, headers=headers)