def transform(tokens):
    """Validation for ``transform``."""
    if get_single_keyword(tokens) == 'none':
        return ()
    else:
        transforms = []
        for token in tokens:
            function = parse_function(token)
            if not function:
                return
            name, args = function

            if len(args) == 1:
                angle = get_angle(args[0])
                length = get_length(args[0], percentage=True)
                if name == 'rotate' and angle is not None:
                    transforms.append((name, angle))
                elif name in ('skewx', 'skew') and angle is not None:
                    transforms.append(('skew', (angle, 0)))
                elif name == 'skewy' and angle is not None:
                    transforms.append(('skew', (0, angle)))
                elif name in ('translatex', 'translate') and length:
                    transforms.append(('translate', (length, ZERO_PIXELS)))
                elif name == 'translatey' and length:
                    transforms.append(('translate', (ZERO_PIXELS, length)))
                elif name == 'scalex' and args[0].type == 'number':
                    transforms.append(('scale', (args[0].value, 1)))
                elif name == 'scaley' and args[0].type == 'number':
                    transforms.append(('scale', (1, args[0].value)))
                elif name == 'scale' and args[0].type == 'number':
                    transforms.append(('scale', (args[0].value,) * 2))
                else:
                    return
            elif len(args) == 2:
                if name == 'scale' and all(a.type == 'number' for a in args):
                    transforms.append((name, tuple(arg.value for arg in args)))
                elif name == 'translate':
                    lengths = tuple(
                        get_length(token, percentage=True) for token in args)
                    if all(lengths):
                        transforms.append((name, lengths))
                    else:
                        return
                elif name == 'skew':
                    angles = tuple(get_angle(token) for token in args)
                    if all(angle is not None for angle in angles):
                        transforms.append((name, angles))
                    else:
                        return
                else:
                    return
            elif len(args) == 6 and name == 'matrix' and all(
                    a.type == 'number' for a in args):
                transforms.append((name, tuple(arg.value for arg in args)))
            else:
                return
        return tuple(transforms)
Validation for ``transform``.
weasyprint/css/validation/properties.py