Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import sys |
| 4 | sys.path.append('./gen-py') |
| 5 | |
| 6 | import ThriftTest |
| 7 | from ThriftTest_types import * |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 8 | from thrift.transport import TTransport |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 9 | from thrift.transport import TSocket |
| 10 | from thrift.protocol import TBinaryProtocol |
| 11 | from thrift.server import TServer |
| 12 | |
| 13 | class 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 Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 26 | 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 Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 46 | def testException(self, str): |
| 47 | print 'testException(%s)' % str |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 48 | if str == 'Xception': |
| 49 | x = Xception() |
| 50 | x.errorCode = 1001 |
| 51 | x.message = str |
| 52 | raise x |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 53 | |
| 54 | transport = TSocket.TServerSocket(9090) |
| 55 | protocol = TBinaryProtocol.TBinaryProtocol() |
| 56 | handler = TestHandler() |
Mark Slee | 018b699 | 2006-09-07 21:31:12 +0000 | [diff] [blame] | 57 | processor = ThriftTest.Processor(handler, protocol) |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 58 | factory = TTransport.TBufferedTransportFactory() |
Mark Slee | 018b699 | 2006-09-07 21:31:12 +0000 | [diff] [blame] | 59 | server = TServer.TSimpleServer(processor, transport, factory) |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 60 | server.serve() |