def resolve_percentages(box, containing_block):
    """Set used values as attributes of the box object."""
    if isinstance(containing_block, boxes.Box):
        # cb is short for containing block
        cb_width = containing_block.width
        cb_height = containing_block.height
    else:
        cb_width, cb_height = containing_block
    if isinstance(box, boxes.PageBox):
        maybe_height = cb_height
    else:
        maybe_height = cb_width
    resolve_one_percentage(box, 'margin_left', cb_width)
    resolve_one_percentage(box, 'margin_right', cb_width)
    resolve_one_percentage(box, 'margin_top', maybe_height)
    resolve_one_percentage(box, 'margin_bottom', maybe_height)
    resolve_one_percentage(box, 'padding_left', cb_width)
    resolve_one_percentage(box, 'padding_right', cb_width)
    resolve_one_percentage(box, 'padding_top', maybe_height)
    resolve_one_percentage(box, 'padding_bottom', maybe_height)
    resolve_one_percentage(box, 'width', cb_width)
    resolve_one_percentage(box, 'min_width', cb_width)
    resolve_one_percentage(box, 'max_width', cb_width)

    # XXX later: top, bottom, left and right on positioned elements

    if cb_height == 'auto':
        # Special handling when the height of the containing block
        # depends on its content.
        height = box.style['height']
        if height == 'auto' or height.unit == '%':
            box.height = 'auto'
        else:
            assert height.unit == 'px'
            box.height = height.value
        resolve_one_percentage(box, 'min_height', 0)
        resolve_one_percentage(box, 'max_height', inf)
    else:
        resolve_one_percentage(box, 'height', cb_height)
        resolve_one_percentage(box, 'min_height', cb_height)
        resolve_one_percentage(box, 'max_height', cb_height)

    collapse = box.style['border_collapse'] == 'collapse'
    # Used value == computed value
    for side in ('top', 'right', 'bottom', 'left'):
        prop = f'border_{side}_width'
        # border-{side}-width would have been resolved
        # during border conflict resolution for collapsed-borders
        if not (collapse and hasattr(box, prop)):
            setattr(box, prop, box.style[prop])

    # Shrink *content* widths and heights according to box-sizing
    adjust_box_sizing(box, 'width')
    adjust_box_sizing(box, 'height')
Set used values as attributes of the box object.
weasyprint/layout/percent.py