Functest test script file update
[domino.git] / lib / thrift / Thrift.py
1 #
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
20 import sys
21
22
23 class TType:
24   STOP   = 0
25   VOID   = 1
26   BOOL   = 2
27   BYTE   = 3
28   I08    = 3
29   DOUBLE = 4
30   I16    = 6
31   I32    = 8
32   I64    = 10
33   STRING = 11
34   UTF7   = 11
35   STRUCT = 12
36   MAP    = 13
37   SET    = 14
38   LIST   = 15
39   UTF8   = 16
40   UTF16  = 17
41
42   _VALUES_TO_NAMES = ('STOP',
43                       'VOID',
44                       'BOOL',
45                       'BYTE',
46                       'DOUBLE',
47                       None,
48                       'I16',
49                       None,
50                       'I32',
51                       None,
52                      'I64',
53                      'STRING',
54                      'STRUCT',
55                      'MAP',
56                      'SET',
57                      'LIST',
58                      'UTF8',
59                      'UTF16')
60
61
62 class TMessageType:
63   CALL = 1
64   REPLY = 2
65   EXCEPTION = 3
66   ONEWAY = 4
67
68
69 class TProcessor:
70   """Base class for procsessor, which works on two streams."""
71
72   def process(iprot, oprot):
73     pass
74
75
76 class TException(Exception):
77   """Base class for all thrift exceptions."""
78
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):
82       return self._message
83
84     def _set_message(self, message):
85       self._message = message
86     message = property(_get_message, _set_message)
87
88   def __init__(self, message=None):
89     Exception.__init__(self, message)
90     self.message = message
91
92
93 class TApplicationException(TException):
94   """Application level thrift exceptions."""
95
96   UNKNOWN = 0
97   UNKNOWN_METHOD = 1
98   INVALID_MESSAGE_TYPE = 2
99   WRONG_METHOD_NAME = 3
100   BAD_SEQUENCE_ID = 4
101   MISSING_RESULT = 5
102   INTERNAL_ERROR = 6
103   PROTOCOL_ERROR = 7
104   INVALID_TRANSFORM = 8
105   INVALID_PROTOCOL = 9
106   UNSUPPORTED_CLIENT_TYPE = 10
107
108   def __init__(self, type=UNKNOWN, message=None):
109     TException.__init__(self, message)
110     self.type = type
111
112   def __str__(self):
113     if self.message:
114       return 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'
135     else:
136       return 'Default (unknown) TApplicationException'
137
138   def read(self, iprot):
139     iprot.readStructBegin()
140     while True:
141       (fname, ftype, fid) = iprot.readFieldBegin()
142       if ftype == TType.STOP:
143         break
144       if fid == 1:
145         if ftype == TType.STRING:
146           self.message = iprot.readString()
147         else:
148           iprot.skip(ftype)
149       elif fid == 2:
150         if ftype == TType.I32:
151           self.type = iprot.readI32()
152         else:
153           iprot.skip(ftype)
154       else:
155         iprot.skip(ftype)
156       iprot.readFieldEnd()
157     iprot.readStructEnd()
158
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()