]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/py/src/Thrift.py
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
64 class TMessageType(object):
71 class TProcessor(object):
72 """Base class for processor, which works on two streams."""
74 def process(self
, iprot
, oprot
):
76 Process a request. The normal behvaior is to have the
77 processor invoke the correct handler and then it is the
78 server's responsibility to write the response to oprot.
82 def on_message_begin(self
, func
):
84 Install a callback that receives (name, type, seqid)
85 after the message header is read.
90 class TException(Exception):
91 """Base class for all thrift exceptions."""
93 # BaseException.message is deprecated in Python v[2.6,3.0)
94 if (2, 6, 0) <= sys
.version_info
< (3, 0):
95 def _get_message(self
):
98 def _set_message(self
, message
):
99 self
._message
= message
100 message
= property(_get_message
, _set_message
)
102 def __init__(self
, message
=None):
103 Exception.__init
__(self
, message
)
104 self
.message
= message
107 class TApplicationException(TException
):
108 """Application level thrift exceptions."""
112 INVALID_MESSAGE_TYPE
= 2
113 WRONG_METHOD_NAME
= 3
118 INVALID_TRANSFORM
= 8
120 UNSUPPORTED_CLIENT_TYPE
= 10
122 def __init__(self
, type=UNKNOWN
, message
=None):
123 TException
.__init
__(self
, message
)
129 elif self
.type == self
.UNKNOWN_METHOD
:
130 return 'Unknown method'
131 elif self
.type == self
.INVALID_MESSAGE_TYPE
:
132 return 'Invalid message type'
133 elif self
.type == self
.WRONG_METHOD_NAME
:
134 return 'Wrong method name'
135 elif self
.type == self
.BAD_SEQUENCE_ID
:
136 return 'Bad sequence ID'
137 elif self
.type == self
.MISSING_RESULT
:
138 return 'Missing result'
139 elif self
.type == self
.INTERNAL_ERROR
:
140 return 'Internal error'
141 elif self
.type == self
.PROTOCOL_ERROR
:
142 return 'Protocol error'
143 elif self
.type == self
.INVALID_TRANSFORM
:
144 return 'Invalid transform'
145 elif self
.type == self
.INVALID_PROTOCOL
:
146 return 'Invalid protocol'
147 elif self
.type == self
.UNSUPPORTED_CLIENT_TYPE
:
148 return 'Unsupported client type'
150 return 'Default (unknown) TApplicationException'
152 def read(self
, iprot
):
153 iprot
.readStructBegin()
155 (fname
, ftype
, fid
) = iprot
.readFieldBegin()
156 if ftype
== TType
.STOP
:
159 if ftype
== TType
.STRING
:
160 self
.message
= iprot
.readString()
164 if ftype
== TType
.I32
:
165 self
.type = iprot
.readI32()
171 iprot
.readStructEnd()
173 def write(self
, oprot
):
174 oprot
.writeStructBegin('TApplicationException')
175 if self
.message
is not None:
176 oprot
.writeFieldBegin('message', TType
.STRING
, 1)
177 oprot
.writeString(self
.message
)
178 oprot
.writeFieldEnd()
179 if self
.type is not None:
180 oprot
.writeFieldBegin('type', TType
.I32
, 2)
181 oprot
.writeI32(self
.type)
182 oprot
.writeFieldEnd()
183 oprot
.writeFieldStop()
184 oprot
.writeStructEnd()
187 class TFrozenDict(dict):
188 """A dictionary that is "frozen" like a frozenset"""
190 def __init__(self
, *args
, **kwargs
):
191 super(TFrozenDict
, self
).__init
__(*args
, **kwargs
)
192 # Sort the items so they will be in a consistent order.
193 # XOR in the hash of the class so we don't collide with
194 # the hash of a list of tuples.
195 self
.__hashval
= hash(TFrozenDict
) ^
hash(tuple(sorted(self
.items())))
197 def __setitem__(self
, *args
):
198 raise TypeError("Can't modify frozen TFreezableDict")
200 def __delitem__(self
, *args
):
201 raise TypeError("Can't modify frozen TFreezableDict")
204 return self
.__hashval