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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
20 from thrift.Thrift import *
21 from thrift.protocol import TBinaryProtocol
22 from thrift.transport import TTransport
25 from thrift.protocol import fastbinary
34 L = ['%s=%r' % (key, getattr(self, key))
35 for key in self.__slots__]
36 return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
38 def __eq__(self, other):
39 if not isinstance(other, self.__class__):
41 for attr in self.__slots__:
42 my_val = getattr(self, attr)
43 other_val = getattr(other, attr)
44 if my_val != other_val:
48 def __ne__(self, other):
49 return not (self == other)
51 def read(self, iprot):
52 if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
53 isinstance(iprot.trans, TTransport.CReadableTransport) and
54 self.thrift_spec is not None and
55 fastbinary is not None):
56 fastbinary.decode_binary(self,
58 (self.__class__, self.thrift_spec))
60 iprot.readStruct(self, self.thrift_spec)
62 def write(self, oprot):
63 if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
64 self.thrift_spec is not None and
65 fastbinary is not None):
67 fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
69 oprot.writeStruct(self, self.thrift_spec)
72 class TExceptionBase(Exception):
73 # old style class so python2.4 can raise exceptions derived from this
74 # This can't inherit from TBase because of that limitation.
77 __repr__ = TBase.__repr__.im_func
78 __eq__ = TBase.__eq__.im_func
79 __ne__ = TBase.__ne__.im_func
80 read = TBase.read.im_func
81 write = TBase.write.im_func