def distribute_excess_width(context, grid, excess_width, column_widths, constrainedness,
                            column_intrinsic_percentages, column_max_content_widths,
                            column_slice=slice(0, None)):
    """Distribute available width to columns.

    See https://www.w3.org/TR/css-tables-3/#distributing-width-to-columns

    """
    # First group.
    columns = [
        i for i, _ in enumerate(grid[column_slice], start=column_slice.start)
        if not constrainedness[i] and
        column_intrinsic_percentages[i] == 0 and
        column_max_content_widths[i] > 0]
    if columns:
        sum_max_content_widths = sum(column_max_content_widths[i] for i in columns)
        ratio = excess_width / sum_max_content_widths
        for i in columns:
            column_widths[i] += column_max_content_widths[i] * ratio
        return

    # Second group.
    columns = [
        i for i, _ in enumerate(grid[column_slice], start=column_slice.start)
        if not constrainedness[i] and column_intrinsic_percentages[i] == 0]
    if columns:
        for i in columns:
            column_widths[i] += excess_width / len(columns)
        return

    # Third group.
    columns = [
        i for i, _ in enumerate(grid[column_slice], start=column_slice.start)
        if constrainedness[i] and
        column_intrinsic_percentages[i] == 0 and
        column_max_content_widths[i] > 0]
    if columns:
        sum_max_content_widths = sum(column_max_content_widths[i] for i in columns)
        ratio = excess_width / sum_max_content_widths
        for i in columns:
            column_widths[i] += column_max_content_widths[i] * ratio
        return

    # Fourth group.
    columns = [
        i for i, _ in enumerate(grid[column_slice], start=column_slice.start)
        if column_intrinsic_percentages[i] > 0 and column_max_content_widths[i] > 0]
    if columns:
        sum_intrinsic_percentages = sum(
            column_intrinsic_percentages[i] for i in columns)
        ratio = excess_width / sum_intrinsic_percentages
        for i in columns:
            column_widths[i] += column_intrinsic_percentages[i] * ratio
        return

    # Fifth group.
    columns = [
        i for i, column in enumerate(grid[column_slice], start=column_slice.start)
        if column]
    if columns:
        for i in columns:
            column_widths[i] += excess_width / len(columns)
        return

    # Sixth group.
    columns = [i for i, _ in enumerate(grid[column_slice], start=column_slice.start)]
    for i in columns:
        column_widths[i] += excess_width / len(columns)
Distribute available width to columns.

See https://www.w3.org/TR/css-tables-3/#distributing-width-to-columns
weasyprint/layout/table.py