human
Complete the below
def _validator_events(desc, key, validator, include_removes, include_backrefs):

    ''''Runs a validation method on an attribute value to be set or appended.'
    '''

Can you provide a the Python program you requested?
assistant
#Here is the Python program you requested.
    if (not include_backrefs):
        def detect_is_backref(state, initiator):
            impl = state.manager[key].impl
            return (initiator.impl is not impl)
    if include_removes:
        def append(state, value, initiator):
            if (include_backrefs or (not detect_is_backref(state, initiator))):
                return validator(state.obj(), key, value, False)
            else:
                return value
        def set_(state, value, oldvalue, initiator):
            if (include_backrefs or (not detect_is_backref(state, initiator))):
                return validator(state.obj(), key, value, False)
            else:
                return value
        def remove(state, value, initiator):
            if (include_backrefs or (not detect_is_backref(state, initiator))):
                validator(state.obj(), key, value, True)
    else:
        def append(state, value, initiator):
            if (include_backrefs or (not detect_is_backref(state, initiator))):
                return validator(state.obj(), key, value)
            else:
                return value
        def set_(state, value, oldvalue, initiator):
            if (include_backrefs or (not detect_is_backref(state, initiator))):
                return validator(state.obj(), key, value)
            else:
                return value
    event.listen(desc, 'append', append, raw=True, retval=True)
    event.listen(desc, 'set', set_, raw=True, retval=True)
    if include_removes:
        event.listen(desc, 'remove', remove, raw=True, retval=True)