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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
42 _VALUES_TO_NAMES = ('STOP',
70 """Base class for procsessor, which works on two streams."""
72 def process(iprot, oprot):
76 class TException(Exception):
77 """Base class for all thrift exceptions."""
79 # BaseException.message is deprecated in Python v[2.6,3.0)
80 if (2, 6, 0) <= sys.version_info < (3, 0):
81 def _get_message(self):
84 def _set_message(self, message):
85 self._message = message
86 message = property(_get_message, _set_message)
88 def __init__(self, message=None):
89 Exception.__init__(self, message)
90 self.message = message
93 class TApplicationException(TException):
94 """Application level thrift exceptions."""
98 INVALID_MESSAGE_TYPE = 2
104 INVALID_TRANSFORM = 8
106 UNSUPPORTED_CLIENT_TYPE = 10
108 def __init__(self, type=UNKNOWN, message=None):
109 TException.__init__(self, message)
115 elif self.type == self.UNKNOWN_METHOD:
116 return 'Unknown method'
117 elif self.type == self.INVALID_MESSAGE_TYPE:
118 return 'Invalid message type'
119 elif self.type == self.WRONG_METHOD_NAME:
120 return 'Wrong method name'
121 elif self.type == self.BAD_SEQUENCE_ID:
122 return 'Bad sequence ID'
123 elif self.type == self.MISSING_RESULT:
124 return 'Missing result'
125 elif self.type == self.INTERNAL_ERROR:
126 return 'Internal error'
127 elif self.type == self.PROTOCOL_ERROR:
128 return 'Protocol error'
129 elif self.type == self.INVALID_TRANSFORM:
130 return 'Invalid transform'
131 elif self.type == self.INVALID_PROTOCOL:
132 return 'Invalid protocol'
133 elif self.type == self.UNSUPPORTED_CLIENT_TYPE:
134 return 'Unsupported client type'
136 return 'Default (unknown) TApplicationException'
138 def read(self, iprot):
139 iprot.readStructBegin()
141 (fname, ftype, fid) = iprot.readFieldBegin()
142 if ftype == TType.STOP:
145 if ftype == TType.STRING:
146 self.message = iprot.readString()
150 if ftype == TType.I32:
151 self.type = iprot.readI32()
157 iprot.readStructEnd()
159 def write(self, oprot):
160 oprot.writeStructBegin('TApplicationException')
161 if self.message is not None:
162 oprot.writeFieldBegin('message', TType.STRING, 1)
163 oprot.writeString(self.message)
164 oprot.writeFieldEnd()
165 if self.type is not None:
166 oprot.writeFieldBegin('type', TType.I32, 2)
167 oprot.writeI32(self.type)
168 oprot.writeFieldEnd()
169 oprot.writeFieldStop()
170 oprot.writeStructEnd()