blob: aeca9b9e6e1e5d3ee349c7172fd920b6ee6ea38a [file] [log] [blame]
Mark Slee89e2bb82007-03-01 00:20:36 +00001#!/usr/bin/env python
2#
3# Copyright (c) 2006- Facebook
4# Distributed under the Thrift Software License
5#
6# See accompanying file LICENSE or visit the Thrift site at:
7# http://developers.facebook.com/thrift/
8
Mark Sleee74306a2007-02-21 05:38:12 +00009class TType:
10 STOP = 0
11 VOID = 1
12 BOOL = 2
13 BYTE = 3
14 I08 = 3
15 DOUBLE = 4
16 I16 = 6
17 I32 = 8
18 I64 = 10
19 STRING = 11
20 UTF7 = 11
21 STRUCT = 12
22 MAP = 13
23 SET = 14
24 LIST = 15
25 UTF8 = 16
26 UTF16 = 17
27
28class TMessageType:
29 CALL = 1
30 REPLY = 2
31 EXCEPTION = 3
32
Mark Sleec9676562006-09-05 17:34:52 +000033class TProcessor:
34
35 """Base class for procsessor, which works on two streams."""
36
Mark Slee4ac459f2006-10-25 21:39:01 +000037 def process(iprot, oprot):
Mark Sleec9676562006-09-05 17:34:52 +000038 pass
Mark Slee92195ae2007-02-21 05:16:30 +000039
40class TException(Exception):
41
42 """Base class for all thrift exceptions."""
43
44 def __init__(self, message=None):
45 Exception.__init__(self, message)
Mark Slee76791962007-03-14 02:47:35 +000046 self.message = message
Mark Slee92195ae2007-02-21 05:16:30 +000047
48class TApplicationException(TException):
49
50 """Application level thrift exceptions."""
51
52 UNKNOWN = 0
53 UNKNOWN_METHOD = 1
54 INVALID_MESSAGE_TYPE = 2
55 WRONG_METHOD_NAME = 3
56 BAD_SEQUENCE_ID = 4
57 MISSING_RESULT = 5
58
59 def __init__(self, type=UNKNOWN, message=None):
60 TException.__init__(self, message)
61 self.type = type
62
63 def read(self, iprot):
64 iprot.readStructBegin()
65 while True:
66 (fname, ftype, fid) = iprot.readFieldBegin()
67 if ftype == TType.STOP:
68 break
69 if fid == 1:
70 if ftype == TType.STRING:
71 self.message = iprot.readString();
72 else:
73 iprot.skip(ftype)
74 elif fid == 2:
75 if ftype == TType.I32:
76 self.type = iprot.readI32();
77 else:
78 iprot.skip(ftype)
79 else:
80 iprot.skip(ftype)
81 iprot.readFieldEnd()
82 iprot.readStructEnd()
83
84 def write(self, oprot):
85 oprot.writeStructBegin('TApplicationException')
86 if self.message != None:
87 oprot.writeFieldBegin('message', TType.STRING, 1)
88 oprot.writeString(self.message)
89 oprot.writeFieldEnd()
90 if self.type != None:
91 oprot.writeFieldBegin('type', TType.I32, 2)
92 oprot.writeI32(self.type)
93 oprot.writeFieldEnd()
94 oprot.writeFieldStop()
95 oprot.writeStructEnd()