blob: 81689b70b8242ef601dca9755f0db37335268b60 [file] [log] [blame]
Mark Sleec9676562006-09-05 17:34:52 +00001class TProcessor:
2
3 """Base class for procsessor, which works on two streams."""
4
Mark Slee4ac459f2006-10-25 21:39:01 +00005 def process(iprot, oprot):
Mark Sleec9676562006-09-05 17:34:52 +00006 pass
Mark Slee92195ae2007-02-21 05:16:30 +00007
8class TException(Exception):
9
10 """Base class for all thrift exceptions."""
11
12 def __init__(self, message=None):
13 Exception.__init__(self, message)
14
15class TApplicationException(TException):
16
17 """Application level thrift exceptions."""
18
19 UNKNOWN = 0
20 UNKNOWN_METHOD = 1
21 INVALID_MESSAGE_TYPE = 2
22 WRONG_METHOD_NAME = 3
23 BAD_SEQUENCE_ID = 4
24 MISSING_RESULT = 5
25
26 def __init__(self, type=UNKNOWN, message=None):
27 TException.__init__(self, message)
28 self.type = type
29
30 def read(self, iprot):
31 iprot.readStructBegin()
32 while True:
33 (fname, ftype, fid) = iprot.readFieldBegin()
34 if ftype == TType.STOP:
35 break
36 if fid == 1:
37 if ftype == TType.STRING:
38 self.message = iprot.readString();
39 else:
40 iprot.skip(ftype)
41 elif fid == 2:
42 if ftype == TType.I32:
43 self.type = iprot.readI32();
44 else:
45 iprot.skip(ftype)
46 else:
47 iprot.skip(ftype)
48 iprot.readFieldEnd()
49 iprot.readStructEnd()
50
51 def write(self, oprot):
52 oprot.writeStructBegin('TApplicationException')
53 if self.message != None:
54 oprot.writeFieldBegin('message', TType.STRING, 1)
55 oprot.writeString(self.message)
56 oprot.writeFieldEnd()
57 if self.type != None:
58 oprot.writeFieldBegin('type', TType.I32, 2)
59 oprot.writeI32(self.type)
60 oprot.writeFieldEnd()
61 oprot.writeFieldStop()
62 oprot.writeStructEnd()