2 # Autogenerated by Thrift
4 # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
8 from __future__
import absolute_import
10 from thrift
.util
.Recursive
import fix_spec
11 from thrift
.Thrift
import TType
, TMessageType
, TPriority
, TRequestContext
, TProcessorEventHandler
, TServerInterface
, TProcessor
, TException
, TApplicationException
, UnimplementedTypedef
12 from thrift
.protocol
.TProtocol
import TProtocolException
14 from json
import loads
16 if sys
.version_info
[0] >= 3:
19 from .ttypes
import UTF8STRINGS
, MyEnum
, MyStructNestedAnnotation
, MyUnion
, MyException
, MyStruct
, SecretStruct
, MyId
20 import thrift
.annotation
.cpp
.ttypes
22 from thrift
.Thrift
import TProcessor
25 from thrift
import Thrift
26 from thrift
.transport
import TTransport
27 from thrift
.protocol
import TBinaryProtocol
28 from thrift
.protocol
import TCompactProtocol
29 from thrift
.protocol
import THeaderProtocol
32 from thrift
.protocol
import fastproto
37 UTF8STRINGS
= bool(0) or sys
.version_info
.major
>= 3
39 from thrift
.util
.Decorators
import (
41 future_process_method
,
42 process_main
as thrift_process_main
,
43 process_method
as thrift_process_method
,
45 write_results_after_future
,
50 "cpp.name": "GoodService",
59 "cpp.name": "GoodService",
62 def bar(self
, handler_ctx
, ):
66 # HELPER FUNCTIONS AND STRUCTURES
71 thrift_field_annotations
= None
72 thrift_struct_annotations
= None
77 def read(self
, iprot
):
78 if (isinstance(iprot
, TBinaryProtocol
.TBinaryProtocolAccelerated
) or (isinstance(iprot
, THeaderProtocol
.THeaderProtocolAccelerate
) and iprot
.get_protocol_id() == THeaderProtocol
.THeaderProtocol
.T_BINARY_PROTOCOL
)) and isinstance(iprot
.trans
, TTransport
.CReadableTransport
) and self
.thrift_spec
is not None and fastproto
is not None:
79 fastproto
.decode(self
, iprot
.trans
, [self
.__class
__, self
.thrift_spec
, False], utf8strings
=UTF8STRINGS
, protoid
=0)
81 if (isinstance(iprot
, TCompactProtocol
.TCompactProtocolAccelerated
) or (isinstance(iprot
, THeaderProtocol
.THeaderProtocolAccelerate
) and iprot
.get_protocol_id() == THeaderProtocol
.THeaderProtocol
.T_COMPACT_PROTOCOL
)) and isinstance(iprot
.trans
, TTransport
.CReadableTransport
) and self
.thrift_spec
is not None and fastproto
is not None:
82 fastproto
.decode(self
, iprot
.trans
, [self
.__class
__, self
.thrift_spec
, False], utf8strings
=UTF8STRINGS
, protoid
=2)
84 iprot
.readStructBegin()
86 (fname
, ftype
, fid
) = iprot
.readFieldBegin()
87 if ftype
== TType
.STOP
:
94 def write(self
, oprot
):
95 if (isinstance(oprot
, TBinaryProtocol
.TBinaryProtocolAccelerated
) or (isinstance(oprot
, THeaderProtocol
.THeaderProtocolAccelerate
) and oprot
.get_protocol_id() == THeaderProtocol
.THeaderProtocol
.T_BINARY_PROTOCOL
)) and self
.thrift_spec
is not None and fastproto
is not None:
96 oprot
.trans
.write(fastproto
.encode(self
, [self
.__class
__, self
.thrift_spec
, False], utf8strings
=UTF8STRINGS
, protoid
=0))
98 if (isinstance(oprot
, TCompactProtocol
.TCompactProtocolAccelerated
) or (isinstance(oprot
, THeaderProtocol
.THeaderProtocolAccelerate
) and oprot
.get_protocol_id() == THeaderProtocol
.THeaderProtocol
.T_COMPACT_PROTOCOL
)) and self
.thrift_spec
is not None and fastproto
is not None:
99 oprot
.trans
.write(fastproto
.encode(self
, [self
.__class
__, self
.thrift_spec
, False], utf8strings
=UTF8STRINGS
, protoid
=2))
101 oprot
.writeStructBegin('bar_args')
102 oprot
.writeFieldStop()
103 oprot
.writeStructEnd()
105 def readFromJson(self
, json
, is_text
=True, **kwargs
):
106 relax_enum_validation
= bool(kwargs
.pop('relax_enum_validation', False))
107 set_cls
= kwargs
.pop('custom_set_cls', set)
108 dict_cls
= kwargs
.pop('custom_dict_cls', dict)
110 extra_kwargs
= ', '.join(kwargs
.keys())
112 'Unexpected keyword arguments: ' + extra_kwargs
116 json_obj
= loads(json
)
121 return "%s(%s)" % (self
.__class
__.__name
__, "\n" + ",\n".join(L
) if L
else '')
123 def __eq__(self
, other
):
124 if not isinstance(other
, self
.__class
__):
127 return self
.__dict
__ == other
.__dict
__
129 def __ne__(self
, other
):
130 return not (self
== other
)
136 # Override the __hash__ function for Python3 - t10434117
137 __hash__
= object.__hash
__
139 all_structs
.append(bar_args
)
140 bar_args
.thrift_spec
= (
143 bar_args
.thrift_struct_annotations
= {
145 bar_args
.thrift_field_annotations
= {
155 thrift_field_annotations
= None
156 thrift_struct_annotations
= None
162 def read(self
, iprot
):
163 if (isinstance(iprot
, TBinaryProtocol
.TBinaryProtocolAccelerated
) or (isinstance(iprot
, THeaderProtocol
.THeaderProtocolAccelerate
) and iprot
.get_protocol_id() == THeaderProtocol
.THeaderProtocol
.T_BINARY_PROTOCOL
)) and isinstance(iprot
.trans
, TTransport
.CReadableTransport
) and self
.thrift_spec
is not None and fastproto
is not None:
164 fastproto
.decode(self
, iprot
.trans
, [self
.__class
__, self
.thrift_spec
, False], utf8strings
=UTF8STRINGS
, protoid
=0)
166 if (isinstance(iprot
, TCompactProtocol
.TCompactProtocolAccelerated
) or (isinstance(iprot
, THeaderProtocol
.THeaderProtocolAccelerate
) and iprot
.get_protocol_id() == THeaderProtocol
.THeaderProtocol
.T_COMPACT_PROTOCOL
)) and isinstance(iprot
.trans
, TTransport
.CReadableTransport
) and self
.thrift_spec
is not None and fastproto
is not None:
167 fastproto
.decode(self
, iprot
.trans
, [self
.__class
__, self
.thrift_spec
, False], utf8strings
=UTF8STRINGS
, protoid
=2)
169 iprot
.readStructBegin()
171 (fname
, ftype
, fid
) = iprot
.readFieldBegin()
172 if ftype
== TType
.STOP
:
175 if ftype
== TType
.I32
:
176 self
.success
= iprot
.readI32()
182 iprot
.readStructEnd()
184 def write(self
, oprot
):
185 if (isinstance(oprot
, TBinaryProtocol
.TBinaryProtocolAccelerated
) or (isinstance(oprot
, THeaderProtocol
.THeaderProtocolAccelerate
) and oprot
.get_protocol_id() == THeaderProtocol
.THeaderProtocol
.T_BINARY_PROTOCOL
)) and self
.thrift_spec
is not None and fastproto
is not None:
186 oprot
.trans
.write(fastproto
.encode(self
, [self
.__class
__, self
.thrift_spec
, False], utf8strings
=UTF8STRINGS
, protoid
=0))
188 if (isinstance(oprot
, TCompactProtocol
.TCompactProtocolAccelerated
) or (isinstance(oprot
, THeaderProtocol
.THeaderProtocolAccelerate
) and oprot
.get_protocol_id() == THeaderProtocol
.THeaderProtocol
.T_COMPACT_PROTOCOL
)) and self
.thrift_spec
is not None and fastproto
is not None:
189 oprot
.trans
.write(fastproto
.encode(self
, [self
.__class
__, self
.thrift_spec
, False], utf8strings
=UTF8STRINGS
, protoid
=2))
191 oprot
.writeStructBegin('bar_result')
192 if self
.success
!= None:
193 oprot
.writeFieldBegin('success', TType
.I32
, 0)
194 oprot
.writeI32(self
.success
)
195 oprot
.writeFieldEnd()
196 oprot
.writeFieldStop()
197 oprot
.writeStructEnd()
199 def readFromJson(self
, json
, is_text
=True, **kwargs
):
200 relax_enum_validation
= bool(kwargs
.pop('relax_enum_validation', False))
201 set_cls
= kwargs
.pop('custom_set_cls', set)
202 dict_cls
= kwargs
.pop('custom_dict_cls', dict)
204 extra_kwargs
= ', '.join(kwargs
.keys())
206 'Unexpected keyword arguments: ' + extra_kwargs
210 json_obj
= loads(json
)
211 if 'success' in json_obj
and json_obj
['success'] is not None:
212 self
.success
= json_obj
['success']
213 if self
.success
> 0x7fffffff or self
.success
< -0x80000000:
214 raise TProtocolException(TProtocolException
.INVALID_DATA
, 'number exceeds limit in field')
219 if self
.success
is not None:
220 value
= pprint
.pformat(self
.success
, indent
=0)
221 value
= padding
.join(value
.splitlines(True))
222 L
.append(' success=%s' % (value
))
223 return "%s(%s)" % (self
.__class
__.__name
__, "\n" + ",\n".join(L
) if L
else '')
225 def __eq__(self
, other
):
226 if not isinstance(other
, self
.__class
__):
229 return self
.__dict
__ == other
.__dict
__
231 def __ne__(self
, other
):
232 return not (self
== other
)
239 # Override the __hash__ function for Python3 - t10434117
240 __hash__
= object.__hash
__
242 all_structs
.append(bar_result
)
243 bar_result
.thrift_spec
= (
244 (0, TType
.I32
, 'success', None, None, 2, ), # 0
247 bar_result
.thrift_struct_annotations
= {
249 bar_result
.thrift_field_annotations
= {
252 def bar_result__init__(self
, success
=None,):
253 self
.success
= success
255 bar_result
.__init
__ = bar_result__init__
257 def bar_result__setstate__(self
, state
):
258 state
.setdefault('success', None)
259 self
.__dict
__ = state
261 bar_result
.__getstate
__ = lambda self
: self
.__dict
__.copy()
262 bar_result
.__setstate
__ = bar_result__setstate__
265 _fbthrift_force_cpp_transport
= False
268 if self
._fbthrift
_cpp
_transport
:
269 self
._fbthrift
_cpp
_transport
.__enter
__()
272 def __exit__(self
, type, value
, tb
):
273 if self
._fbthrift
_cpp
_transport
:
274 self
._fbthrift
_cpp
_transport
.__exit
__(type, value
, tb
)
276 self
._iprot
.trans
.close()
277 if self
._oprot
and self
._iprot
is not self
._oprot
:
278 self
._oprot
.trans
.close()
280 def __init__(self
, iprot
=None, oprot
=None, cpp_transport
=None):
281 self
._iprot
= self
._oprot
= iprot
285 self
._fbthrift
_cpp
_transport
= cpp_transport
287 def set_persistent_header(self
, key
, value
):
288 if self
._fbthrift
_cpp
_transport
:
289 self
._fbthrift
_cpp
_transport
.set_persistent_header(key
, value
)
292 self
._oprot
.trans
.set_persistent_header(key
, value
)
293 except AttributeError:
296 def get_persistent_headers(self
):
297 if self
._fbthrift
_cpp
_transport
:
298 return self
._fbthrift
_cpp
_transport
.get_persistent_headers()
300 return self
._oprot
.trans
.get_write_persistent_headers()
301 except AttributeError:
304 def clear_persistent_headers(self
):
305 if self
._fbthrift
_cpp
_transport
:
306 self
._fbthrift
_cpp
_transport
.clear_persistent_headers()
309 self
._oprot
.trans
.clear_persistent_headers()
310 except AttributeError:
313 def set_onetime_header(self
, key
, value
):
314 if self
._fbthrift
_cpp
_transport
:
315 self
._fbthrift
_cpp
_transport
.set_onetime_header(key
, value
)
318 self
._oprot
.trans
.set_header(key
, value
)
319 except AttributeError:
322 def get_last_response_headers(self
):
323 if self
._fbthrift
_cpp
_transport
:
324 return self
._fbthrift
_cpp
_transport
.get_last_response_headers()
326 return self
._iprot
.trans
.get_headers()
327 except AttributeError:
330 def set_max_frame_size(self
, size
):
331 if self
._fbthrift
_cpp
_transport
:
335 self
._oprot
.trans
.set_max_frame_size(size
)
336 except AttributeError:
340 if (self
._fbthrift
_cpp
_transport
):
342 result
= self
._fbthrift
_cpp
_transport
._send
_request
("BadService", "bar", args
, bar_result
)
343 if result
.success
is not None:
344 return result
.success
345 raise TApplicationException(TApplicationException
.MISSING_RESULT
)
347 return self
.recv_bar()
349 def send_bar(self
, ):
350 self
._oprot
.writeMessageBegin('bar', TMessageType
.CALL
, self
._seqid
)
352 args
.write(self
._oprot
)
353 self
._oprot
.writeMessageEnd()
354 self
._oprot
.trans
.flush()
356 def recv_bar(self
, ):
357 (fname
, mtype
, rseqid
) = self
._iprot
.readMessageBegin()
358 if mtype
== TMessageType
.EXCEPTION
:
359 x
= TApplicationException()
361 self
._iprot
.readMessageEnd()
363 result
= bar_result()
364 result
.read(self
._iprot
)
365 self
._iprot
.readMessageEnd()
366 if result
.success
!= None:
367 return result
.success
368 raise TApplicationException(TApplicationException
.MISSING_RESULT
, "bar failed: unknown result");
371 class Processor(Iface
, TProcessor
):
374 def __init__(self
, handler
):
375 TProcessor
.__init
__(self
)
376 self
._handler
= handler
377 self
._processMap
= {}
378 self
._priorityMap
= {}
379 self
._processMap
["bar"] = Processor
.process_bar
380 self
._priorityMap
["bar"] = TPriority
.NORMAL
382 def onewayMethods(self
):
384 l
.extend(Processor
._onewayMethods
)
387 @thrift_process_main()
388 def process(self
,): pass
390 @thrift_process_method(bar_args
, oneway
=False)
391 def process_bar(self
, args
, handler_ctx
):
392 result
= bar_result()
394 result
.success
= self
._handler
.bar()
396 ex
= sys
.exc_info()[1]
397 self
._event
_handler
.handlerError(handler_ctx
, 'bar', ex
)
398 result
= Thrift
.TApplicationException(message
=repr(ex
))
401 Iface
._processor
_type
= Processor
403 class ContextProcessor(ContextIface
, TProcessor
):
406 def __init__(self
, handler
):
407 TProcessor
.__init
__(self
)
408 self
._handler
= handler
409 self
._processMap
= {}
410 self
._priorityMap
= {}
411 self
._processMap
["bar"] = ContextProcessor
.process_bar
412 self
._priorityMap
["bar"] = TPriority
.NORMAL
414 def onewayMethods(self
):
416 l
.extend(ContextProcessor
._onewayMethods
)
419 @thrift_process_main()
420 def process(self
,): pass
422 @thrift_process_method(bar_args
, oneway
=False)
423 def process_bar(self
, args
, handler_ctx
):
424 result
= bar_result()
426 result
.success
= self
._handler
.bar(handler_ctx
)
428 ex
= sys
.exc_info()[1]
429 self
._event
_handler
.handlerError(handler_ctx
, 'bar', ex
)
430 result
= Thrift
.TApplicationException(message
=repr(ex
))
433 ContextIface
._processor
_type
= ContextProcessor
435 fix_spec(all_structs
)