<s> import cbor , msgpack , msgpackrpc , sys , os , threading <EOL> def get_test_data_list ( ) : <EOL> l0 = [ <EOL> - <NUM_LIT:8> , <EOL> - <NUM_LIT> , <EOL> - <NUM_LIT> , <EOL> - <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> - <NUM_LIT> , <EOL> - <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> False , <EOL> True , <EOL> None , <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> <NUM_LIT> , <EOL> - <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> - <NUM_LIT> , <EOL> ] <EOL> l1 = [ <EOL> { "<STR_LIT:true>" : True , <EOL> "<STR_LIT:false>" : False } , <EOL> { "<STR_LIT:true>" : "<STR_LIT:True>" , <EOL> "<STR_LIT:false>" : False , <EOL> "<STR_LIT>" : <NUM_LIT> } , <EOL> { "<STR_LIT:list>" : [ <NUM_LIT> , <NUM_LIT> , True , - <NUM_LIT> , { "<STR_LIT>" : True , "<STR_LIT>" : False } , [ True , False ] ] , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT:bool>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> { True : "<STR_LIT:true>" , <NUM_LIT:8> : False , "<STR_LIT:false>" : <NUM_LIT:0> } <EOL> ] <EOL> l = [ ] <EOL> l . extend ( l0 ) <EOL> l . append ( l0 ) <EOL> l . extend ( l1 ) <EOL> return l <EOL> def build_test_data ( destdir ) : <EOL> l = get_test_data_list ( ) <EOL> for i in range ( len ( l ) ) : <EOL> serialized = msgpack . dumps ( l [ i ] ) <EOL> f = open ( os . path . join ( destdir , str ( i ) + '<STR_LIT>' ) , '<STR_LIT:wb>' ) <EOL> f . write ( serialized ) <EOL> f . close ( ) <EOL> serialized = cbor . dumps ( l [ i ] ) <EOL> f = open ( os . path . join ( destdir , str ( i ) + '<STR_LIT>' ) , '<STR_LIT:wb>' ) <EOL> f . write ( serialized ) <EOL> f . close ( ) <EOL> def doRpcServer ( port , stopTimeSec ) : <EOL> class EchoHandler ( object ) : <EOL> def Echo123 ( self , msg1 , msg2 , msg3 ) : <EOL> return ( "<STR_LIT>" % ( msg1 , msg2 , msg3 ) ) <EOL> def EchoStruct ( self , msg ) : <EOL> return ( "<STR_LIT:%s>" % msg ) <EOL> addr = msgpackrpc . Address ( '<STR_LIT:localhost>' , port ) <EOL> server = msgpackrpc . Server ( EchoHandler ( ) ) <EOL> server . listen ( addr ) <EOL> if stopTimeSec > <NUM_LIT:0> : <EOL> def myStopRpcServer ( ) : <EOL> server . stop ( ) <EOL> t = threading . Timer ( stopTimeSec , myStopRpcServer ) <EOL> t . start ( ) <EOL> server . start ( ) <EOL> def doRpcClientToPythonSvc ( port ) : <EOL> address = msgpackrpc . Address ( '<STR_LIT:localhost>' , port ) <EOL> client = msgpackrpc . Client ( address , unpack_encoding = '<STR_LIT:utf-8>' ) <EOL> print client . call ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> print client . call ( "<STR_LIT>" , { "<STR_LIT:A>" : "<STR_LIT>" , "<STR_LIT:B>" : "<STR_LIT>" , "<STR_LIT:C>" : "<STR_LIT>" } ) <EOL> def doRpcClientToGoSvc ( port ) : <EOL> address = msgpackrpc . Address ( '<STR_LIT:localhost>' , port ) <EOL> client = msgpackrpc . Client ( address , unpack_encoding = '<STR_LIT:utf-8>' ) <EOL> print client . call ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> print client . call ( "<STR_LIT>" , { "<STR_LIT:A>" : "<STR_LIT>" , "<STR_LIT:B>" : "<STR_LIT>" , "<STR_LIT:C>" : "<STR_LIT>" } ) <EOL> def doMain ( args ) : <EOL> if len ( args ) == <NUM_LIT:2> and args [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> build_test_data ( args [ <NUM_LIT:1> ] ) <EOL> elif len ( args ) == <NUM_LIT:3> and args [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> doRpcServer ( int ( args [ <NUM_LIT:1> ] ) , int ( args [ <NUM_LIT:2> ] ) ) <EOL> elif len ( args ) == <NUM_LIT:2> and args [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> doRpcClientToPythonSvc ( int ( args [ <NUM_LIT:1> ] ) ) <EOL> elif len ( args ) == <NUM_LIT:2> and args [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> doRpcClientToGoSvc ( int ( args [ <NUM_LIT:1> ] ) ) <EOL> else : <EOL> print ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> doMain ( sys . argv [ <NUM_LIT:1> : ] ) </s>
