Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/env python## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.#import sys, glob, timesys.path.insert(0, './gen-py')sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])from ThriftTest import ThriftTestfrom ThriftTest.ttypes import *from thrift.transport import TTransportfrom thrift.transport import TSocketfrom thrift.protocol import TBinaryProtocolfrom thrift.server import TServer, TNonblockingServer, THttpServerclass TestHandler:def testVoid(self):print 'testVoid()'def testString(self, str):print 'testString(%s)' % strreturn strdef testByte(self, byte):print 'testByte(%d)' % bytereturn bytedef testI16(self, i16):print 'testI16(%d)' % i16return i16def testI32(self, i32):print 'testI32(%d)' % i32return i32def testI64(self, i64):print 'testI64(%d)' % i64return i64def testDouble(self, dub):print 'testDouble(%f)' % dubreturn dubdef testStruct(self, thing):print 'testStruct({%s, %d, %d, %d})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing)return thingdef testException(self, str):print 'testException(%s)' % strif str == 'Xception':x = Xception()x.errorCode = 1001x.message = strraise xelif str == "throw_undeclared":raise ValueError("foo")def testOneway(self, seconds):print 'testOneway(%d) => sleeping...' % secondstime.sleep(seconds)print 'done sleeping'def testNest(self, thing):return thingdef testMap(self, thing):return thingdef testSet(self, thing):return thingdef testList(self, thing):return thingdef testEnum(self, thing):return thingdef testTypedef(self, thing):return thingpfactory = TBinaryProtocol.TBinaryProtocolFactory()handler = TestHandler()processor = ThriftTest.Processor(handler)if sys.argv[1] == "THttpServer":server = THttpServer.THttpServer(processor, ('', 9090), pfactory)else:transport = TSocket.TServerSocket(9090)tfactory = TTransport.TBufferedTransportFactory()if sys.argv[1] == "TNonblockingServer":server = TNonblockingServer.TNonblockingServer(processor, transport)else:ServerClass = getattr(TServer, sys.argv[1])server = ServerClass(processor, transport, tfactory, pfactory)server.serve()