Skip to content

Instantly share code, notes, and snippets.

@Sorseg
Created September 10, 2014 09:50
Show Gist options
  • Save Sorseg/ca2c35ac813c558f90d1 to your computer and use it in GitHub Desktop.
Save Sorseg/ca2c35ac813c558f90d1 to your computer and use it in GitHub Desktop.
import json
class DispatcherBase:
switch = 'what'
def __call__(self, act):
if not isinstance(act, dict):
act = json.loads(act)
what = act.pop(self.switch, None)
if what is None:
raise ValueError("{} is not registered in {}".format(what, self))
return getattr(self, 'do_'+what)(**act)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment