blob: f0f9ba1120e2e68b5595259f2bd67d6c933e2af6 [file] [log] [blame]
Mark Sleec9676562006-09-05 17:34:52 +00001#!/usr/bin/python
2
3import sys
4sys.path.append('./gen-py')
5
6import ThriftTest
7from ThriftTest_types import *
Mark Sleed788b2e2006-09-07 01:26:35 +00008from thrift.transport import TTransport
Mark Sleec9676562006-09-05 17:34:52 +00009from thrift.transport import TSocket
10from thrift.protocol import TBinaryProtocol
11from thrift.server import TServer
12
13class TestHandler:
14
15 def testVoid(self):
16 print 'testVoid()'
17
18 def testString(self, str):
19 print 'testString(%s)' % str
20 return str
21
22 def testByte(self, byte):
23 print 'testByte(%d)' % byte
24 return byte
25
Mark Sleec98d0502006-09-06 02:42:25 +000026 def testI16(self, i16):
27 print 'testI16(%d)' % i16
28 return i16
29
30 def testI32(self, i32):
31 print 'testI32(%d)' % i32
32 return i32
33
34 def testI64(self, i64):
35 print 'testI64(%d)' % i64
36 return i64
37
38 def testDouble(self, dub):
39 print 'testDouble(%f)' % dub
40 return dub
41
42 def testStruct(self, thing):
43 print 'testStruct({%s, %d, %d, %d})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing)
44 return thing
45
Mark Sleec9676562006-09-05 17:34:52 +000046 def testException(self, str):
47 print 'testException(%s)' % str
Mark Sleec98d0502006-09-06 02:42:25 +000048 if str == 'Xception':
49 x = Xception()
50 x.errorCode = 1001
51 x.message = str
52 raise x
Mark Sleec9676562006-09-05 17:34:52 +000053
54transport = TSocket.TServerSocket(9090)
55protocol = TBinaryProtocol.TBinaryProtocol()
56handler = TestHandler()
Mark Slee018b6992006-09-07 21:31:12 +000057processor = ThriftTest.Processor(handler, protocol)
Mark Sleed788b2e2006-09-07 01:26:35 +000058factory = TTransport.TBufferedTransportFactory()
Mark Slee018b6992006-09-07 21:31:12 +000059server = TServer.TSimpleServer(processor, transport, factory)
Mark Sleec9676562006-09-05 17:34:52 +000060server.run()