blob: a1ec6cccd2ddffd758c6edfbef763d7b6dd3a5ef [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)
46
47class TApplicationException(TException):
48
49 """Application level thrift exceptions."""
50
51 UNKNOWN = 0
52 UNKNOWN_METHOD = 1
53 INVALID_MESSAGE_TYPE = 2
54 WRONG_METHOD_NAME = 3
55 BAD_SEQUENCE_ID = 4
56 MISSING_RESULT = 5
57
58 def __init__(self, type=UNKNOWN, message=None):
59 TException.__init__(self, message)
60 self.type = type
61
62 def read(self, iprot):
63 iprot.readStructBegin()
64 while True:
65 (fname, ftype, fid) = iprot.readFieldBegin()
66 if ftype == TType.STOP:
67 break
68 if fid == 1:
69 if ftype == TType.STRING:
70 self.message = iprot.readString();
71 else:
72 iprot.skip(ftype)
73 elif fid == 2:
74 if ftype == TType.I32:
75 self.type = iprot.readI32();
76 else:
77 iprot.skip(ftype)
78 else:
79 iprot.skip(ftype)
80 iprot.readFieldEnd()
81 iprot.readStructEnd()
82
83 def write(self, oprot):
84 oprot.writeStructBegin('TApplicationException')
85 if self.message != None:
86 oprot.writeFieldBegin('message', TType.STRING, 1)
87 oprot.writeString(self.message)
88 oprot.writeFieldEnd()
89 if self.type != None:
90 oprot.writeFieldBegin('type', TType.I32, 2)
91 oprot.writeI32(self.type)
92 oprot.writeFieldEnd()
93 oprot.writeFieldStop()
94 oprot.writeStructEnd()