blob: 0ef9b198b443266a7fb573c35726d29675e45f68 [file] [log] [blame]
Mark Slee89e2bb82007-03-01 00:20:36 +00001# Copyright (c) 2006- Facebook
2# Distributed under the Thrift Software License
3#
4# See accompanying file LICENSE or visit the Thrift site at:
5# http://developers.facebook.com/thrift/
6
Mark Sleee74306a2007-02-21 05:38:12 +00007class TType:
8 STOP = 0
9 VOID = 1
10 BOOL = 2
11 BYTE = 3
12 I08 = 3
13 DOUBLE = 4
14 I16 = 6
15 I32 = 8
16 I64 = 10
17 STRING = 11
18 UTF7 = 11
19 STRUCT = 12
20 MAP = 13
21 SET = 14
22 LIST = 15
23 UTF8 = 16
24 UTF16 = 17
25
26class TMessageType:
27 CALL = 1
28 REPLY = 2
29 EXCEPTION = 3
30
Mark Sleec9676562006-09-05 17:34:52 +000031class TProcessor:
32
33 """Base class for procsessor, which works on two streams."""
34
Mark Slee4ac459f2006-10-25 21:39:01 +000035 def process(iprot, oprot):
Mark Sleec9676562006-09-05 17:34:52 +000036 pass
Mark Slee92195ae2007-02-21 05:16:30 +000037
38class TException(Exception):
39
40 """Base class for all thrift exceptions."""
41
42 def __init__(self, message=None):
43 Exception.__init__(self, message)
Mark Slee76791962007-03-14 02:47:35 +000044 self.message = message
Mark Slee92195ae2007-02-21 05:16:30 +000045
46class TApplicationException(TException):
47
48 """Application level thrift exceptions."""
49
50 UNKNOWN = 0
51 UNKNOWN_METHOD = 1
52 INVALID_MESSAGE_TYPE = 2
53 WRONG_METHOD_NAME = 3
54 BAD_SEQUENCE_ID = 4
55 MISSING_RESULT = 5
56
57 def __init__(self, type=UNKNOWN, message=None):
58 TException.__init__(self, message)
59 self.type = type
60
dweatherford33d8f342008-01-07 22:23:07 +000061 def __str__(self):
62 if self.message:
63 return self.message
64 elif self.type == UNKNOWN_METHOD:
65 return 'Unknown method'
66 elif self.type == INVALID_MESSAGE_TYPE:
67 return 'Invalid message type'
68 elif self.type == WRONG_METHOD_NAME:
69 return 'Wrong method name'
70 elif self.type == BAD_SEQUENCE_ID:
71 return 'Bad sequence ID'
72 elif self.type == MISSING_RESULT:
73 return 'Missing result'
74 else:
75 return 'Default (unknown) TApplicationException'
76
Mark Slee92195ae2007-02-21 05:16:30 +000077 def read(self, iprot):
78 iprot.readStructBegin()
79 while True:
80 (fname, ftype, fid) = iprot.readFieldBegin()
81 if ftype == TType.STOP:
82 break
83 if fid == 1:
84 if ftype == TType.STRING:
85 self.message = iprot.readString();
86 else:
87 iprot.skip(ftype)
88 elif fid == 2:
89 if ftype == TType.I32:
90 self.type = iprot.readI32();
91 else:
92 iprot.skip(ftype)
93 else:
94 iprot.skip(ftype)
95 iprot.readFieldEnd()
96 iprot.readStructEnd()
97
98 def write(self, oprot):
99 oprot.writeStructBegin('TApplicationException')
100 if self.message != None:
101 oprot.writeFieldBegin('message', TType.STRING, 1)
102 oprot.writeString(self.message)
103 oprot.writeFieldEnd()
104 if self.type != None:
105 oprot.writeFieldBegin('type', TType.I32, 2)
106 oprot.writeI32(self.type)
107 oprot.writeFieldEnd()
108 oprot.writeFieldStop()
109 oprot.writeStructEnd()