From 11cdbe590955af0fa484cd790fee783db7ac425a Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 20 Oct 2017 10:37:23 -0400 Subject: [PATCH] Allow using latest version of thrift --- setup.py | 4 +- test/scales/thrift/gen_py/hello/Hello.py | 455 +++++++++---------- test/scales/thrift/gen_py/hello/__init__.py | 2 +- test/scales/thrift/gen_py/hello/constants.py | 23 +- test/scales/thrift/gen_py/hello/ttypes.py | 31 +- test/scales/thrift/hello.thrift | 3 + 6 files changed, 256 insertions(+), 262 deletions(-) create mode 100644 test/scales/thrift/hello.thrift diff --git a/setup.py b/setup.py index cd6b853..bc8fceb 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='scales-rpc', - version='1.0.7', + version='1.1.0', author='Steve Niemitz', author_email='sniemitz@twitter.com', url='https://www.github.com/steveniemitz/scales', @@ -21,7 +21,7 @@ 'scales.thriftmux'], install_requires=[ 'gevent>=0.13.8', - 'thrift>=0.5.0,<=0.9.3', + 'thrift>=0.5.0', 'kazoo>=1.3.1', 'requests>=2.0.0'] ) diff --git a/test/scales/thrift/gen_py/hello/Hello.py b/test/scales/thrift/gen_py/hello/Hello.py index 3fe8219..5f42fb0 100644 --- a/test/scales/thrift/gen_py/hello/Hello.py +++ b/test/scales/thrift/gen_py/hello/Hello.py @@ -1,230 +1,225 @@ -# -# Autogenerated by Thrift Compiler (0.9.2) -# -# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -# -# options string: py -# - -from thrift.Thrift import TType, TMessageType, TException, TApplicationException -from ttypes import * -from thrift.Thrift import TProcessor -from thrift.transport import TTransport -from thrift.protocol import TBinaryProtocol, TProtocol -try: - from thrift.protocol import fastbinary -except: - fastbinary = None - - -class Iface: - def hi(self, test_data): - """ - Parameters: - - test_data - """ - pass - - -class Client(Iface): - def __init__(self, iprot, oprot=None): - self._iprot = self._oprot = iprot - if oprot is not None: - self._oprot = oprot - self._seqid = 0 - - def hi(self, test_data): - """ - Parameters: - - test_data - """ - self.send_hi(test_data) - return self.recv_hi() - - def send_hi(self, test_data): - self._oprot.writeMessageBegin('hi', TMessageType.CALL, self._seqid) - args = hi_args() - args.test_data = test_data - args.write(self._oprot) - self._oprot.writeMessageEnd() - self._oprot.trans.flush() - - def recv_hi(self): - iprot = self._iprot - (fname, mtype, rseqid) = iprot.readMessageBegin() - if mtype == TMessageType.EXCEPTION: - x = TApplicationException() - x.read(iprot) - iprot.readMessageEnd() - raise x - result = hi_result() - result.read(iprot) - iprot.readMessageEnd() - if result.success is not None: - return result.success - raise TApplicationException(TApplicationException.MISSING_RESULT, "hi failed: unknown result"); - - -class Processor(Iface, TProcessor): - def __init__(self, handler): - self._handler = handler - self._processMap = {} - self._processMap["hi"] = Processor.process_hi - - def process(self, iprot, oprot): - (name, type, seqid) = iprot.readMessageBegin() - if name not in self._processMap: - iprot.skip(TType.STRUCT) - iprot.readMessageEnd() - x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) - oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) - x.write(oprot) - oprot.writeMessageEnd() - oprot.trans.flush() - return - else: - self._processMap[name](self, seqid, iprot, oprot) - return True - - def process_hi(self, seqid, iprot, oprot): - args = hi_args() - args.read(iprot) - iprot.readMessageEnd() - result = hi_result() - result.success = self._handler.hi(args.test_data) - oprot.writeMessageBegin("hi", TMessageType.REPLY, seqid) - result.write(oprot) - oprot.writeMessageEnd() - oprot.trans.flush() - - -# HELPER FUNCTIONS AND STRUCTURES - -class hi_args: - """ - Attributes: - - test_data - """ - - thrift_spec = ( - None, # 0 - (1, TType.STRING, 'test_data', None, None, ), # 1 - ) - - def __init__(self, test_data=None,): - self.test_data = test_data - - def read(self, iprot): - if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: - fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec)) - return - iprot.readStructBegin() - while True: - (fname, ftype, fid) = iprot.readFieldBegin() - if ftype == TType.STOP: - break - if fid == 1: - if ftype == TType.STRING: - self.test_data = iprot.readString(); - else: - iprot.skip(ftype) - else: - iprot.skip(ftype) - iprot.readFieldEnd() - iprot.readStructEnd() - - def write(self, oprot): - if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: - oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) - return - oprot.writeStructBegin('hi_args') - if self.test_data is not None: - oprot.writeFieldBegin('test_data', TType.STRING, 1) - oprot.writeString(self.test_data) - oprot.writeFieldEnd() - oprot.writeFieldStop() - oprot.writeStructEnd() - - def validate(self): - return - - - def __hash__(self): - value = 17 - value = (value * 31) ^ hash(self.test_data) - return value - - def __repr__(self): - L = ['%s=%r' % (key, value) - for key, value in self.__dict__.iteritems()] - return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) - - def __eq__(self, other): - return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not (self == other) - -class hi_result: - """ - Attributes: - - success - """ - - thrift_spec = ( - (0, TType.STRING, 'success', None, None, ), # 0 - ) - - def __init__(self, success=None,): - self.success = success - - def read(self, iprot): - if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: - fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec)) - return - iprot.readStructBegin() - while True: - (fname, ftype, fid) = iprot.readFieldBegin() - if ftype == TType.STOP: - break - if fid == 0: - if ftype == TType.STRING: - self.success = iprot.readString(); - else: - iprot.skip(ftype) - else: - iprot.skip(ftype) - iprot.readFieldEnd() - iprot.readStructEnd() - - def write(self, oprot): - if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: - oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) - return - oprot.writeStructBegin('hi_result') - if self.success is not None: - oprot.writeFieldBegin('success', TType.STRING, 0) - oprot.writeString(self.success) - oprot.writeFieldEnd() - oprot.writeFieldStop() - oprot.writeStructEnd() - - def validate(self): - return - - - def __hash__(self): - value = 17 - value = (value * 31) ^ hash(self.success) - return value - - def __repr__(self): - L = ['%s=%r' % (key, value) - for key, value in self.__dict__.iteritems()] - return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) - - def __eq__(self, other): - return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not (self == other) +# +# Autogenerated by Thrift Compiler (0.10.0) +# +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +# +# options string: py +# + +from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException +from thrift.protocol.TProtocol import TProtocolException +import sys +import logging +from .ttypes import * +from thrift.Thrift import TProcessor +from thrift.transport import TTransport + + +class Iface(object): + def hi(self, test_data): + """ + Parameters: + - test_data + """ + pass + + +class Client(Iface): + def __init__(self, iprot, oprot=None): + self._iprot = self._oprot = iprot + if oprot is not None: + self._oprot = oprot + self._seqid = 0 + + def hi(self, test_data): + """ + Parameters: + - test_data + """ + self.send_hi(test_data) + return self.recv_hi() + + def send_hi(self, test_data): + self._oprot.writeMessageBegin('hi', TMessageType.CALL, self._seqid) + args = hi_args() + args.test_data = test_data + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_hi(self): + iprot = self._iprot + (fname, mtype, rseqid) = iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(iprot) + iprot.readMessageEnd() + raise x + result = hi_result() + result.read(iprot) + iprot.readMessageEnd() + if result.success is not None: + return result.success + raise TApplicationException(TApplicationException.MISSING_RESULT, "hi failed: unknown result") + + +class Processor(Iface, TProcessor): + def __init__(self, handler): + self._handler = handler + self._processMap = {} + self._processMap["hi"] = Processor.process_hi + + def process(self, iprot, oprot): + (name, type, seqid) = iprot.readMessageBegin() + if name not in self._processMap: + iprot.skip(TType.STRUCT) + iprot.readMessageEnd() + x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) + oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) + x.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + return + else: + self._processMap[name](self, seqid, iprot, oprot) + return True + + def process_hi(self, seqid, iprot, oprot): + args = hi_args() + args.read(iprot) + iprot.readMessageEnd() + result = hi_result() + try: + result.success = self._handler.hi(args.test_data) + msg_type = TMessageType.REPLY + except (TTransport.TTransportException, KeyboardInterrupt, SystemExit): + raise + except Exception as ex: + msg_type = TMessageType.EXCEPTION + logging.exception(ex) + result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') + oprot.writeMessageBegin("hi", msg_type, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + +# HELPER FUNCTIONS AND STRUCTURES + + +class hi_args(object): + """ + Attributes: + - test_data + """ + + thrift_spec = ( + None, # 0 + (1, TType.STRING, 'test_data', 'UTF8', None, ), # 1 + ) + + def __init__(self, test_data=None,): + self.test_data = test_data + + def read(self, iprot): + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: + iprot._fast_decode(self, iprot, (self.__class__, self.thrift_spec)) + return + iprot.readStructBegin() + while True: + (fname, ftype, fid) = iprot.readFieldBegin() + if ftype == TType.STOP: + break + if fid == 1: + if ftype == TType.STRING: + self.test_data = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + else: + iprot.skip(ftype) + iprot.readFieldEnd() + iprot.readStructEnd() + + def write(self, oprot): + if oprot._fast_encode is not None and self.thrift_spec is not None: + oprot.trans.write(oprot._fast_encode(self, (self.__class__, self.thrift_spec))) + return + oprot.writeStructBegin('hi_args') + if self.test_data is not None: + oprot.writeFieldBegin('test_data', TType.STRING, 1) + oprot.writeString(self.test_data.encode('utf-8') if sys.version_info[0] == 2 else self.test_data) + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + + def validate(self): + return + + def __repr__(self): + L = ['%s=%r' % (key, value) + for key, value in self.__dict__.items()] + return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) + + def __eq__(self, other): + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ + + def __ne__(self, other): + return not (self == other) + + +class hi_result(object): + """ + Attributes: + - success + """ + + thrift_spec = ( + (0, TType.STRING, 'success', 'UTF8', None, ), # 0 + ) + + def __init__(self, success=None,): + self.success = success + + def read(self, iprot): + if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: + iprot._fast_decode(self, iprot, (self.__class__, self.thrift_spec)) + return + iprot.readStructBegin() + while True: + (fname, ftype, fid) = iprot.readFieldBegin() + if ftype == TType.STOP: + break + if fid == 0: + if ftype == TType.STRING: + self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + else: + iprot.skip(ftype) + else: + iprot.skip(ftype) + iprot.readFieldEnd() + iprot.readStructEnd() + + def write(self, oprot): + if oprot._fast_encode is not None and self.thrift_spec is not None: + oprot.trans.write(oprot._fast_encode(self, (self.__class__, self.thrift_spec))) + return + oprot.writeStructBegin('hi_result') + if self.success is not None: + oprot.writeFieldBegin('success', TType.STRING, 0) + oprot.writeString(self.success.encode('utf-8') if sys.version_info[0] == 2 else self.success) + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + + def validate(self): + return + + def __repr__(self): + L = ['%s=%r' % (key, value) + for key, value in self.__dict__.items()] + return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) + + def __eq__(self, other): + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ + + def __ne__(self, other): + return not (self == other) diff --git a/test/scales/thrift/gen_py/hello/__init__.py b/test/scales/thrift/gen_py/hello/__init__.py index 4865e6d..2997b42 100644 --- a/test/scales/thrift/gen_py/hello/__init__.py +++ b/test/scales/thrift/gen_py/hello/__init__.py @@ -1 +1 @@ -__all__ = ['ttypes', 'constants', 'Hello'] +__all__ = ['ttypes', 'constants', 'Hello'] diff --git a/test/scales/thrift/gen_py/hello/constants.py b/test/scales/thrift/gen_py/hello/constants.py index 336462a..eb0d35a 100644 --- a/test/scales/thrift/gen_py/hello/constants.py +++ b/test/scales/thrift/gen_py/hello/constants.py @@ -1,11 +1,12 @@ -# -# Autogenerated by Thrift Compiler (0.9.2) -# -# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -# -# options string: py -# - -from thrift.Thrift import TType, TMessageType, TException, TApplicationException -from ttypes import * - +# +# Autogenerated by Thrift Compiler (0.10.0) +# +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +# +# options string: py +# + +from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException +from thrift.protocol.TProtocol import TProtocolException +import sys +from .ttypes import * diff --git a/test/scales/thrift/gen_py/hello/ttypes.py b/test/scales/thrift/gen_py/hello/ttypes.py index ed7f32c..d7e97e9 100644 --- a/test/scales/thrift/gen_py/hello/ttypes.py +++ b/test/scales/thrift/gen_py/hello/ttypes.py @@ -1,18 +1,13 @@ -# -# Autogenerated by Thrift Compiler (0.9.2) -# -# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -# -# options string: py -# - -from thrift.Thrift import TType, TMessageType, TException, TApplicationException - -from thrift.transport import TTransport -from thrift.protocol import TBinaryProtocol, TProtocol -try: - from thrift.protocol import fastbinary -except: - fastbinary = None - - +# +# Autogenerated by Thrift Compiler (0.10.0) +# +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +# +# options string: py +# + +from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException +from thrift.protocol.TProtocol import TProtocolException +import sys + +from thrift.transport import TTransport diff --git a/test/scales/thrift/hello.thrift b/test/scales/thrift/hello.thrift new file mode 100644 index 0000000..9f9a737 --- /dev/null +++ b/test/scales/thrift/hello.thrift @@ -0,0 +1,3 @@ +service Hello { + string hi(1: string test_data); +}