Test exception that mimics generated immutable exception behavior.
| 61 | |
| 62 | |
| 63 | class ImmutableException(TException): |
| 64 | """Test exception that mimics generated immutable exception behavior.""" |
| 65 | |
| 66 | thrift_spec = ( |
| 67 | None, # 0 |
| 68 | (1, 11, 'message', 'UTF8', None, ), # 1: string |
| 69 | ) |
| 70 | |
| 71 | def __init__(self, message=None): |
| 72 | super(ImmutableException, self).__init__(message) |
| 73 | |
| 74 | def __setattr__(self, *args): |
| 75 | raise TypeError("can't modify immutable instance") |
| 76 | |
| 77 | def __delattr__(self, *args): |
| 78 | raise TypeError("can't modify immutable instance") |
| 79 | |
| 80 | def __hash__(self): |
| 81 | return hash(self.__class__) ^ hash((self.message,)) |
| 82 | |
| 83 | def __eq__(self, other): |
| 84 | return isinstance(other, self.__class__) and self.message == other.message |
| 85 | |
| 86 | def write(self, oprot): |
| 87 | if oprot._fast_encode is not None and self.thrift_spec is not None: |
| 88 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
| 89 | return |
| 90 | oprot.writeStructBegin('ImmutableException') |
| 91 | if self.message is not None: |
| 92 | oprot.writeFieldBegin('message', 11, 1) |
| 93 | oprot.writeString(self.message) |
| 94 | oprot.writeFieldEnd() |
| 95 | oprot.writeFieldStop() |
| 96 | oprot.writeStructEnd() |
| 97 | |
| 98 | @classmethod |
| 99 | def read(cls, iprot): |
| 100 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and cls.thrift_spec is not None: |
| 101 | return iprot._fast_decode(None, iprot, [cls, cls.thrift_spec]) |
| 102 | return iprot.readStruct(cls, cls.thrift_spec, True) |
| 103 | |
| 104 | |
| 105 | class MutableException(TException): |
no outgoing calls