def expand_four_sides(tokens, name, base_url):
    """Expand properties setting a token for the four sides of a box."""
    # Define expanded names.
    expanded_names = []
    for suffix in ('-top', '-right', '-bottom', '-left'):
        if (i := name.rfind('-')) == -1:
            expanded_names.append(f'{name}{suffix}')
        else:
            # eg. border-color becomes border-*-color, not border-color-*
            expanded_names.append(f'{name[:i]}{suffix}{name[i:]}')

    # Return pending expanders if var is found.
    expander = functools.partial(
        expand_four_sides, name=name, base_url=base_url)
    if result := _find_var(tokens, expander, expanded_names):
        yield from result.items()
        return

    # Make sure we have 4 tokens.
    if len(tokens) == 1:
        tokens *= 4
    elif len(tokens) == 2:
        tokens *= 2  # (bottom, left) defaults to (top, right)
    elif len(tokens) == 3:
        tokens += (tokens[1],)  # left defaults to right
    elif len(tokens) != 4:
        raise InvalidValues(
            f'Expected 1 to 4 token components got {len(tokens)}')
    for expanded_name, token in zip(expanded_names, tokens):
        # validate_non_shorthand returns ((name, value),), we want
        # to yield (name, value).
        result, = validate_non_shorthand(
            [token], expanded_name, base_url, required=True)
        yield result
Expand properties setting a token for the four sides of a box.
weasyprint/css/validation/expanders.py