2007-02-28 21:43:54 +00:00
|
|
|
#!/usr/bin/env python
|
2006-09-05 17:34:52 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
sys.path.append('./gen-py')
|
|
|
|
|
2007-02-28 21:43:54 +00:00
|
|
|
from ThriftTest import ThriftTest
|
|
|
|
from ThriftTest.ttypes import *
|
2006-09-07 01:26:35 +00:00
|
|
|
from thrift.transport import TTransport
|
2006-09-05 17:34:52 +00:00
|
|
|
from thrift.transport import TSocket
|
|
|
|
from thrift.protocol import TBinaryProtocol
|
|
|
|
from thrift.server import TServer
|
|
|
|
|
|
|
|
class TestHandler:
|
|
|
|
|
|
|
|
def testVoid(self):
|
|
|
|
print 'testVoid()'
|
|
|
|
|
|
|
|
def testString(self, str):
|
|
|
|
print 'testString(%s)' % str
|
|
|
|
return str
|
|
|
|
|
|
|
|
def testByte(self, byte):
|
|
|
|
print 'testByte(%d)' % byte
|
|
|
|
return byte
|
|
|
|
|
2006-09-06 02:42:25 +00:00
|
|
|
def testI16(self, i16):
|
|
|
|
print 'testI16(%d)' % i16
|
|
|
|
return i16
|
|
|
|
|
|
|
|
def testI32(self, i32):
|
|
|
|
print 'testI32(%d)' % i32
|
|
|
|
return i32
|
|
|
|
|
|
|
|
def testI64(self, i64):
|
|
|
|
print 'testI64(%d)' % i64
|
|
|
|
return i64
|
|
|
|
|
|
|
|
def testDouble(self, dub):
|
|
|
|
print 'testDouble(%f)' % dub
|
|
|
|
return dub
|
|
|
|
|
|
|
|
def testStruct(self, thing):
|
|
|
|
print 'testStruct({%s, %d, %d, %d})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing)
|
|
|
|
return thing
|
|
|
|
|
2006-09-05 17:34:52 +00:00
|
|
|
def testException(self, str):
|
|
|
|
print 'testException(%s)' % str
|
2006-09-06 02:42:25 +00:00
|
|
|
if str == 'Xception':
|
|
|
|
x = Xception()
|
|
|
|
x.errorCode = 1001
|
|
|
|
x.message = str
|
|
|
|
raise x
|
2006-09-05 17:34:52 +00:00
|
|
|
|
|
|
|
handler = TestHandler()
|
2006-10-26 04:56:18 +00:00
|
|
|
processor = ThriftTest.Processor(handler)
|
|
|
|
transport = TSocket.TServerSocket(9090)
|
|
|
|
tfactory = TTransport.TBufferedTransportFactory()
|
|
|
|
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
|
|
|
|
server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
|
2006-09-20 01:56:10 +00:00
|
|
|
server.serve()
|