<s> class Dispatch ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . functions = dict ( ) <EOL> def call ( self , function , args = ( ) , kwargs = { } ) : <EOL> """<STR_LIT>""" <EOL> return self . functions [ function ] ( * args , ** kwargs ) <EOL> def add ( self , fn , name = None ) : <EOL> """<STR_LIT>""" <EOL> if not name : <EOL> name = fn . __name__ <EOL> self . functions [ name ] = fn <EOL> def remote ( fn , name = None , types = None ) : <EOL> """<STR_LIT>""" <EOL> if not name : <EOL> name = fn . __name__ <EOL> fn . remote = { "<STR_LIT:name>" : name , "<STR_LIT>" : types } <EOL> return fn <EOL> class ObjectDispatch ( Dispatch ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> Dispatch . __init__ ( self ) <EOL> self . obj = obj <EOL> attrs = dir ( self . obj ) <EOL> for attr in attrs : <EOL> a = getattr ( self . obj , attr ) <EOL> if hasattr ( a , '<STR_LIT>' ) : <EOL> self . add ( a , a . remote [ '<STR_LIT:name>' ] ) </s>
