This repository has been archived on 2018-06-04. You can view files and clone it, but cannot push or open issues/pull-requests.
thrift-helloworld/server.py

40 lines
1.0 KiB
Python

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):
return "pong"
def sayHello(self, 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.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
print 'Starting server...'
server.serve()
print('done!')