Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 1 | # |
| 2 | # Licensed to the Apache Software Foundation (ASF) under one |
| 3 | # or more contributor license agreements. See the NOTICE file |
| 4 | # distributed with this work for additional information |
| 5 | # regarding copyright ownership. The ASF licenses this file |
| 6 | # to you under the Apache License, Version 2.0 (the |
| 7 | # "License"); you may not use this file except in compliance |
| 8 | # with the License. You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, |
| 13 | # software distributed under the License is distributed on an |
| 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | # KIND, either express or implied. See the License for the |
| 16 | # specific language governing permissions and limitations |
| 17 | # under the License. |
| 18 | # |
| 19 | |
| 20 | from thrift.Thrift import * |
| 21 | from thrift.protocol import TBinaryProtocol |
| 22 | from thrift.transport import TTransport |
| 23 | |
| 24 | try: |
| 25 | from thrift.protocol import fastbinary |
| 26 | except: |
| 27 | fastbinary = None |
| 28 | |
| 29 | class TBase(object): |
| 30 | __slots__ = [] |
| 31 | |
| 32 | def __repr__(self): |
| 33 | L = ['%s=%r' % (key, getattr(self, key)) |
| 34 | for key in self.__slots__ ] |
| 35 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
| 36 | |
| 37 | def __eq__(self, other): |
| 38 | if not isinstance(other, self.__class__): |
| 39 | return False |
| 40 | for attr in self.__slots__: |
| 41 | my_val = getattr(self, attr) |
| 42 | other_val = getattr(other, attr) |
| 43 | if my_val != other_val: |
| 44 | return False |
| 45 | return True |
| 46 | |
| 47 | def __ne__(self, other): |
| 48 | return not (self == other) |
| 49 | |
| 50 | def read(self, iprot): |
| 51 | if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: |
| 52 | fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec)) |
| 53 | return |
| 54 | iprot.readStruct(self, self.thrift_spec) |
| 55 | |
| 56 | def write(self, oprot): |
| 57 | if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: |
| 58 | oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) |
| 59 | return |
| 60 | oprot.writeStruct(self, self.thrift_spec) |
| 61 | |
| 62 | class TExceptionBase(Exception): |
| 63 | # old style class so python2.4 can raise exceptions derived from this |
| 64 | # This can't inherit from TBase because of that limitation. |
| 65 | __slots__ = [] |
| 66 | |
| 67 | __repr__ = TBase.__repr__.im_func |
| 68 | __eq__ = TBase.__eq__.im_func |
| 69 | __ne__ = TBase.__ne__.im_func |
| 70 | read = TBase.read.im_func |
| 71 | write = TBase.write.im_func |
| 72 | |