blob: 68e0bd5c273698c60ab3eaf64a6f91f98e5d18bd [file] [log] [blame]
Mark Slee57cc25e2007-02-28 21:43:54 +00001#!/usr/bin/env python
Mark Sleec9676562006-09-05 17:34:52 +00002
3import sys
4sys.path.append('./gen-py')
5
Mark Slee57cc25e2007-02-28 21:43:54 +00006from ThriftTest import ThriftTest
7from ThriftTest.ttypes 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
Mark Sleec9676562006-09-05 17:34:52 +000054handler = TestHandler()
Mark Slee1dd819c2006-10-26 04:56:18 +000055processor = ThriftTest.Processor(handler)
56transport = TSocket.TServerSocket(9090)
57tfactory = TTransport.TBufferedTransportFactory()
58pfactory = TBinaryProtocol.TBinaryProtocolFactory()
59server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
Mark Slee794993d2006-09-20 01:56:10 +000060server.serve()