

def state_logic(state):
    '\n    State create/replace/reuse logic. The function name is not very good :(\n\n        state      |  other_state  | same source  | what to reuse from other_state\n    ---------------|---------------|--------------|-------------------------------\n       replace     |    replace    |    True      |  uid, buffer, source\n       replace     |    replace    |    False     |  uid, buffer\n       replace     |   no-replace  |    True      |  source\n       replace     |   no-replace  |    False     |  nothing\n      no-replace   |    replace    |    True      |  uid, buffer, source\n      no-replace   |    replace    |    False     |  uid, buffer\n      no-replace   |   no-replace  |    True      |  source\n      no-replace   |   no-replace  |    False     |  nothing\n    '
    in_same_container = filter((lambda s: (s.container == state.container)), states.get_states())
    other = iterator.find((lambda s: ((s.source == state.source) and (s.options['replace'] == True))), in_same_container)
    if other:
        states.remove(other, wipeout_buffer=False)
        state.uid = other.uid
        state.buff = other.buff
        state.source = other.source
        return (state, other)
    other = iterator.find((lambda s: ((s.source != state.source) and (s.options['replace'] == True))), in_same_container)
    if other:
        states.remove(other, wipeout_buffer=False)
        state.uid = other.uid
        state.buff = other.buff
        state.source.populate_candidates()
        ui.set_buffer_contents(state.buff, state.source.formatted_candidates())
        return (state, other)
    other = iterator.find((lambda s: (s.source == state.source)), in_same_container)
    if other:
        state.source = other.source
    else:
        state.source.populate_candidates()
    return (state, None)

dataset/ETHPy150Open azure-satellite/pyunite/pyunite/core.py state_logic/original