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/python/server.py

45 lines
1.2 KiB
Python

#!/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!')