Created
September 10, 2014 09:50
-
-
Save Sorseg/ca2c35ac813c558f90d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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