blob: 601b41cb06baed88ca6047ab13601c7ff5a618e1 [file] [log] [blame]
Mark Slee89e2bb82007-03-01 00:20:36 +00001#
David Reissea2cba82009-03-30 21:35:00 +00002# 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#
Mark Slee89e2bb82007-03-01 00:20:36 +000019
Mark Sleee74306a2007-02-21 05:38:12 +000020class 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
Mark Sleec9676562006-09-05 17:34:52 +000044class TProcessor:
45
46 """Base class for procsessor, which works on two streams."""
47
Mark Slee4ac459f2006-10-25 21:39:01 +000048 def process(iprot, oprot):
Mark Sleec9676562006-09-05 17:34:52 +000049 pass
Mark Slee92195ae2007-02-21 05:16:30 +000050
51class TException(Exception):
52
53 """Base class for all thrift exceptions."""
54
55 def __init__(self, message=None):
56 Exception.__init__(self, message)
Mark Slee76791962007-03-14 02:47:35 +000057 self.message = message
Mark Slee92195ae2007-02-21 05:16:30 +000058
59class TApplicationException(TException):
60
61 """Application level thrift exceptions."""
62
63 UNKNOWN = 0
64 UNKNOWN_METHOD = 1
65 INVALID_MESSAGE_TYPE = 2
66 WRONG_METHOD_NAME = 3
67 BAD_SEQUENCE_ID = 4
68 MISSING_RESULT = 5
69
70 def __init__(self, type=UNKNOWN, message=None):
71 TException.__init__(self, message)
72 self.type = type
73
dweatherford33d8f342008-01-07 22:23:07 +000074 def __str__(self):
75 if self.message:
76 return self.message
77 elif self.type == UNKNOWN_METHOD:
78 return 'Unknown method'
79 elif self.type == INVALID_MESSAGE_TYPE:
80 return 'Invalid message type'
81 elif self.type == WRONG_METHOD_NAME:
82 return 'Wrong method name'
83 elif self.type == BAD_SEQUENCE_ID:
84 return 'Bad sequence ID'
85 elif self.type == MISSING_RESULT:
86 return 'Missing result'
87 else:
88 return 'Default (unknown) TApplicationException'
89
Mark Slee92195ae2007-02-21 05:16:30 +000090 def read(self, iprot):
91 iprot.readStructBegin()
92 while True:
93 (fname, ftype, fid) = iprot.readFieldBegin()
94 if ftype == TType.STOP:
95 break
96 if fid == 1:
97 if ftype == TType.STRING:
98 self.message = iprot.readString();
99 else:
100 iprot.skip(ftype)
101 elif fid == 2:
102 if ftype == TType.I32:
103 self.type = iprot.readI32();
104 else:
105 iprot.skip(ftype)
106 else:
107 iprot.skip(ftype)
108 iprot.readFieldEnd()
109 iprot.readStructEnd()
110
111 def write(self, oprot):
112 oprot.writeStructBegin('TApplicationException')
113 if self.message != None:
114 oprot.writeFieldBegin('message', TType.STRING, 1)
115 oprot.writeString(self.message)
116 oprot.writeFieldEnd()
117 if self.type != None:
118 oprot.writeFieldBegin('type', TType.I32, 2)
119 oprot.writeI32(self.type)
120 oprot.writeFieldEnd()
121 oprot.writeFieldStop()
122 oprot.writeStructEnd()