Mark Slee | e74306a | 2007-02-21 05:38:12 +0000 | [diff] [blame] | 1 | class TType: |
| 2 | STOP = 0 |
| 3 | VOID = 1 |
| 4 | BOOL = 2 |
| 5 | BYTE = 3 |
| 6 | I08 = 3 |
| 7 | DOUBLE = 4 |
| 8 | I16 = 6 |
| 9 | I32 = 8 |
| 10 | I64 = 10 |
| 11 | STRING = 11 |
| 12 | UTF7 = 11 |
| 13 | STRUCT = 12 |
| 14 | MAP = 13 |
| 15 | SET = 14 |
| 16 | LIST = 15 |
| 17 | UTF8 = 16 |
| 18 | UTF16 = 17 |
| 19 | |
| 20 | class TMessageType: |
| 21 | CALL = 1 |
| 22 | REPLY = 2 |
| 23 | EXCEPTION = 3 |
| 24 | |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 25 | class TProcessor: |
| 26 | |
| 27 | """Base class for procsessor, which works on two streams.""" |
| 28 | |
Mark Slee | 4ac459f | 2006-10-25 21:39:01 +0000 | [diff] [blame] | 29 | def process(iprot, oprot): |
Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 30 | pass |
Mark Slee | 92195ae | 2007-02-21 05:16:30 +0000 | [diff] [blame] | 31 | |
| 32 | class TException(Exception): |
| 33 | |
| 34 | """Base class for all thrift exceptions.""" |
| 35 | |
| 36 | def __init__(self, message=None): |
| 37 | Exception.__init__(self, message) |
| 38 | |
| 39 | class TApplicationException(TException): |
| 40 | |
| 41 | """Application level thrift exceptions.""" |
| 42 | |
| 43 | UNKNOWN = 0 |
| 44 | UNKNOWN_METHOD = 1 |
| 45 | INVALID_MESSAGE_TYPE = 2 |
| 46 | WRONG_METHOD_NAME = 3 |
| 47 | BAD_SEQUENCE_ID = 4 |
| 48 | MISSING_RESULT = 5 |
| 49 | |
| 50 | def __init__(self, type=UNKNOWN, message=None): |
| 51 | TException.__init__(self, message) |
| 52 | self.type = type |
| 53 | |
| 54 | def read(self, iprot): |
| 55 | iprot.readStructBegin() |
| 56 | while True: |
| 57 | (fname, ftype, fid) = iprot.readFieldBegin() |
| 58 | if ftype == TType.STOP: |
| 59 | break |
| 60 | if fid == 1: |
| 61 | if ftype == TType.STRING: |
| 62 | self.message = iprot.readString(); |
| 63 | else: |
| 64 | iprot.skip(ftype) |
| 65 | elif fid == 2: |
| 66 | if ftype == TType.I32: |
| 67 | self.type = iprot.readI32(); |
| 68 | else: |
| 69 | iprot.skip(ftype) |
| 70 | else: |
| 71 | iprot.skip(ftype) |
| 72 | iprot.readFieldEnd() |
| 73 | iprot.readStructEnd() |
| 74 | |
| 75 | def write(self, oprot): |
| 76 | oprot.writeStructBegin('TApplicationException') |
| 77 | if self.message != None: |
| 78 | oprot.writeFieldBegin('message', TType.STRING, 1) |
| 79 | oprot.writeString(self.message) |
| 80 | oprot.writeFieldEnd() |
| 81 | if self.type != None: |
| 82 | oprot.writeFieldBegin('type', TType.I32, 2) |
| 83 | oprot.writeI32(self.type) |
| 84 | oprot.writeFieldEnd() |
| 85 | oprot.writeFieldStop() |
| 86 | oprot.writeStructEnd() |