<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def validate_attribute(attr, name, expected_type=None, required=False):
    '''Validates that an attribute meets expectations.

    This function will check if the given attribute value matches a necessary
    type and/or is not None, an empty string, an empty list, etc. It will raise
    suitable exceptions on validation failure.

    @param attr The value to validate.
    @param name The attribute name to use in exceptions.
    @param expected_type The type the value must be. If None, no check is
    performed. If a list, attr must match one type in the list.
    @param required If the value must not be empty, e.g. not an empty string.
    @raises InvalidTypeError
    @raises RequiredAttributeError

    '''
    if expected_type:
        if type(expected_type) == list:
            if not _check_type(attr, expected_type):
                raise InvalidTypeError(name, type(attr), expected_type)
        else:
            if not _check_type(attr, [expected_type]):
                raise InvalidTypeError(name, type(attr), expected_type)
    if required and not attr:
        raise RequiredAttributeError(name)