#!/usr/bin/env python # -*- coding: utf-8 -*- from helloworld import HelloWorld from helloworld.ttypes import * from helloworld.constants import * from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from thrift.server import TServer class HelloWorldHandler: def __init__(self): self.log = {} def ping(self): print 'Recieved Ping... returning pong' return "pong" def sayHello(self, msg): print 'Recieved hello msg: %s' % msg if msg.lang in ('kp', 'kr'): hello = HELLO_IN_KOREAN elif msg.lang == 'fr': hello = HELLO_IN_FRENCH elif msg.lang == 'jp': hello = HELLO_IN_JAPANESE else: hello = HELLO_IN_ENGLISH return '%s %s' % (hello, msg.name) handler = HelloWorldHandler() processor = HelloWorld.Processor(handler) transport = TSocket.TServerSocket('localhost', port=9090) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) print 'Starting server...' server.serve() print('done!')