blob: 6cd9f583aa14d960701b8afa78be7ec60ebdbe1e [file] [log] [blame]
Mark Slee57cc25e2007-02-28 21:43:54 +00001#!/usr/bin/env python
Mark Sleec9676562006-09-05 17:34:52 +00002
Mark Slee5299a952007-10-05 00:13:24 +00003import sys, glob
4sys.path.insert(0, './gen-py')
5sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
Mark Sleec9676562006-09-05 17:34:52 +00006
Mark Slee57cc25e2007-02-28 21:43:54 +00007from ThriftTest import ThriftTest
8from ThriftTest.ttypes import *
Mark Sleed788b2e2006-09-07 01:26:35 +00009from thrift.transport import TTransport
Mark Sleec9676562006-09-05 17:34:52 +000010from thrift.transport import TSocket
11from thrift.protocol import TBinaryProtocol
12from thrift.server import TServer
13
14class TestHandler:
15
16 def testVoid(self):
17 print 'testVoid()'
18
19 def testString(self, str):
20 print 'testString(%s)' % str
21 return str
22
23 def testByte(self, byte):
24 print 'testByte(%d)' % byte
25 return byte
26
Mark Sleec98d0502006-09-06 02:42:25 +000027 def testI16(self, i16):
28 print 'testI16(%d)' % i16
29 return i16
30
31 def testI32(self, i32):
32 print 'testI32(%d)' % i32
33 return i32
34
35 def testI64(self, i64):
36 print 'testI64(%d)' % i64
37 return i64
38
39 def testDouble(self, dub):
40 print 'testDouble(%f)' % dub
41 return dub
42
43 def testStruct(self, thing):
44 print 'testStruct({%s, %d, %d, %d})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing)
45 return thing
46
Mark Sleec9676562006-09-05 17:34:52 +000047 def testException(self, str):
48 print 'testException(%s)' % str
Mark Sleec98d0502006-09-06 02:42:25 +000049 if str == 'Xception':
50 x = Xception()
51 x.errorCode = 1001
52 x.message = str
53 raise x
Mark Sleec9676562006-09-05 17:34:52 +000054
Mark Sleec9676562006-09-05 17:34:52 +000055handler = TestHandler()
Mark Slee1dd819c2006-10-26 04:56:18 +000056processor = ThriftTest.Processor(handler)
57transport = TSocket.TServerSocket(9090)
58tfactory = TTransport.TBufferedTransportFactory()
59pfactory = TBinaryProtocol.TBinaryProtocolFactory()
60server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
Mark Slee794993d2006-09-20 01:56:10 +000061server.serve()