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

def search_onfail_requisites(sid, highstate):
    '''
    For a particular low chunk, search relevant onfail related states
    '''
    onfails = []
    if '_|-' in sid:
        st = salt.state.split_low_tag(sid)
    else:
        st = {'__id__': sid}
    for fstate, fchunks in six.iteritems(highstate):
        if fstate == st['__id__']:
            continue
        else:
            for mod_, fchunk in six.iteritems(fchunks):
                if (
                    not isinstance(mod_, six.string_types) or
                    mod_.startswith('__')
                ):
                    continue
                else:
                    if not isinstance(fchunk, list):
                        continue
                    else:
                        # bydefault onfail will fail, but you can
                        # set onfail_stop: False to prevent the highstate
                        # to stop if you handle it
                        onfail_handled = False
                        for fdata in fchunk:
                            if not isinstance(fdata, dict):
                                continue
                            onfail_handled = (fdata.get('onfail_stop', True)
                                              is False)
                            if onfail_handled:
                                break
                        if not onfail_handled:
                            continue
                        for fdata in fchunk:
                            if not isinstance(fdata, dict):
                                continue
                            for knob, fvalue in six.iteritems(fdata):
                                if knob != 'onfail':
                                    continue
                                for freqs in fvalue:
                                    for fmod, fid in six.iteritems(freqs):
                                        if not (
                                            fid == st['__id__'] and
                                            fmod == st.get('state', fmod)
                                        ):
                                            continue
                                        onfails.append((fstate, mod_, fchunk))
    return onfails