from apollo_utils.core.utils.dispatchers.arg_dispatcher import ArgValueDispatcher class DspArgDispatcher(ArgValueDispatcher): """DSP Dispatcher based on "dsp" arg key DspArgDispatcher can be used directly or there is an implemented decorator @dsp_dispatch Direct Usage Example: class DSP(Enum): A = "a" B = "b" def get_a_value(dsp, value=1): print(f"A value is {value}") def get_b_value(dsp, value=2): print(f"B value is {value}") We store a DspArgDispatcher in a variable that can be called as a function with args and kwargs and will return the handler for provided _arg_key ("dsp" in current case): get_dsp_playlists_images = DspArgDispatcher( mapper=[(DSP.A, get_a_value),(DSP.B, get_b_value)], name="get_dsp_value" ) CALL & OUTPUT: get_dsp_playlists_images(dsp=DSP.A, value=5) get_dsp_playlists_images(dsp=DSP.B, value=6) A value is 5 B value is 6 """ _arg_key = "dsp" def dsp_dispatch(*args): """A dsp_dispatch decorator is used to add different implementations of the same methods based on DSP Usage Example: class DSP(Enum): A = "a" B = "b" def get_a_value(dsp, value=1): print(f"A value is {value}") def get_b_value(dsp, value=2): print(f"B value is {value}") @dsp_dispatch( (DSP.A, get_a_value), (DSP.B, get_b_value) ) def get_dsp_value(dsp, value): pass CALL & OUTPUT: get_dsp_value(dsp=DSP.A, value=5) get_dsp_value(dsp=DSP.B, value=6) A value is 5 B value is 6 """ mapping = args def _dsp_dispatch(f): return DspArgDispatcher(mapping, f.__name__, f) return _dsp_dispatch