blob: 21d7aa4e5196251fac232d7ae0901ba80bf3a888 [file] [log] [blame]
Gavin McDonald0b75e1a2010-10-28 02:12:01 +00001#
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
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
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
17# under the License.
18#
19
20class TType:
21 STOP = 0
22 VOID = 1
23 BOOL = 2
24 BYTE = 3
25 I08 = 3
26 DOUBLE = 4
27 I16 = 6
28 I32 = 8
29 I64 = 10
30 STRING = 11
31 UTF7 = 11
32 STRUCT = 12
33 MAP = 13
34 SET = 14
35 LIST = 15
36 UTF8 = 16
37 UTF16 = 17
38
39class TMessageType:
40 CALL = 1
41 REPLY = 2
42 EXCEPTION = 3
43 ONEWAY = 4
44
45class TProcessor:
46
47 """Base class for procsessor, which works on two streams."""
48
49 def process(iprot, oprot):
50 pass
51
52class TException(Exception):
53
54 """Base class for all thrift exceptions."""
55
56 def __init__(self, message=None):
57 Exception.__init__(self, message)
58 self.message = message
59
60class TApplicationException(TException):
61
62 """Application level thrift exceptions."""
63
64 UNKNOWN = 0
65 UNKNOWN_METHOD = 1
66 INVALID_MESSAGE_TYPE = 2
67 WRONG_METHOD_NAME = 3
68 BAD_SEQUENCE_ID = 4
69 MISSING_RESULT = 5
70
71 def __init__(self, type=UNKNOWN, message=None):
72 TException.__init__(self, message)
73 self.type = type
74
75 def __str__(self):
76 if self.message:
77 return self.message
78 elif self.type == UNKNOWN_METHOD:
79 return 'Unknown method'
80 elif self.type == INVALID_MESSAGE_TYPE:
81 return 'Invalid message type'
82 elif self.type == WRONG_METHOD_NAME:
83 return 'Wrong method name'
84 elif self.type == BAD_SEQUENCE_ID:
85 return 'Bad sequence ID'
86 elif self.type == MISSING_RESULT:
87 return 'Missing result'
88 else:
89 return 'Default (unknown) TApplicationException'
90
91 def read(self, iprot):
92 iprot.readStructBegin()
93 while True:
94 (fname, ftype, fid) = iprot.readFieldBegin()
95 if ftype == TType.STOP:
96 break
97 if fid == 1:
98 if ftype == TType.STRING:
99 self.message = iprot.readString();
100 else:
101 iprot.skip(ftype)
102 elif fid == 2:
103 if ftype == TType.I32:
104 self.type = iprot.readI32();
105 else:
106 iprot.skip(ftype)
107 else:
108 iprot.skip(ftype)
109 iprot.readFieldEnd()
110 iprot.readStructEnd()
111
112 def write(self, oprot):
113 oprot.writeStructBegin('TApplicationException')
114 if self.message != None:
115 oprot.writeFieldBegin('message', TType.STRING, 1)
116 oprot.writeString(self.message)
117 oprot.writeFieldEnd()
118 if self.type != None:
119 oprot.writeFieldBegin('type', TType.I32, 2)
120 oprot.writeI32(self.type)
121 oprot.writeFieldEnd()
122 oprot.writeFieldStop()
123 oprot.writeStructEnd()