Re-sync with internal repository
[hiphop-php.git] / third-party / thrift / src / thrift / compiler / test / fixtures / basic-annotations / gen-py / module / BadService.py
blob461c77a685d47fd69ca7c8a7f1cf69c8b25af7d5
2 # Autogenerated by Thrift
4 # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 # @generated
8 from __future__ import absolute_import
9 import sys
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
15 import sys
16 if sys.version_info[0] >= 3:
17 long = int
19 from .ttypes import UTF8STRINGS, MyEnum, MyStructNestedAnnotation, MyUnion, MyException, MyStruct, SecretStruct, MyId
20 import thrift.annotation.cpp.ttypes
22 from thrift.Thrift import TProcessor
23 import pprint
24 import warnings
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
30 fastproto = None
31 try:
32 from thrift.protocol import fastproto
33 except ImportError:
34 pass
36 all_structs = []
37 UTF8STRINGS = bool(0) or sys.version_info.major >= 3
39 from thrift.util.Decorators import (
40 future_process_main,
41 future_process_method,
42 process_main as thrift_process_main,
43 process_method as thrift_process_method,
44 should_run_on_thread,
45 write_results_after_future,
48 class Iface:
49 annotations = {
50 "cpp.name": "GoodService",
53 def bar(self, ):
54 pass
57 class ContextIface:
58 annotations = {
59 "cpp.name": "GoodService",
62 def bar(self, handler_ctx, ):
63 pass
66 # HELPER FUNCTIONS AND STRUCTURES
68 class bar_args:
70 thrift_spec = None
71 thrift_field_annotations = None
72 thrift_struct_annotations = None
73 @staticmethod
74 def isUnion():
75 return False
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)
80 return
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)
83 return
84 iprot.readStructBegin()
85 while True:
86 (fname, ftype, fid) = iprot.readFieldBegin()
87 if ftype == TType.STOP:
88 break
89 else:
90 iprot.skip(ftype)
91 iprot.readFieldEnd()
92 iprot.readStructEnd()
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))
97 return
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))
100 return
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)
109 if kwargs:
110 extra_kwargs = ', '.join(kwargs.keys())
111 raise ValueError(
112 'Unexpected keyword arguments: ' + extra_kwargs
114 json_obj = json
115 if is_text:
116 json_obj = loads(json)
118 def __repr__(self):
119 L = []
120 padding = ' ' * 4
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__):
125 return False
127 return self.__dict__ == other.__dict__
129 def __ne__(self, other):
130 return not (self == other)
132 def __dir__(self):
133 return (
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 = {
148 class bar_result:
150 Attributes:
151 - success
154 thrift_spec = None
155 thrift_field_annotations = None
156 thrift_struct_annotations = None
157 __init__ = None
158 @staticmethod
159 def isUnion():
160 return False
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)
165 return
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)
168 return
169 iprot.readStructBegin()
170 while True:
171 (fname, ftype, fid) = iprot.readFieldBegin()
172 if ftype == TType.STOP:
173 break
174 if fid == 0:
175 if ftype == TType.I32:
176 self.success = iprot.readI32()
177 else:
178 iprot.skip(ftype)
179 else:
180 iprot.skip(ftype)
181 iprot.readFieldEnd()
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))
187 return
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))
190 return
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)
203 if kwargs:
204 extra_kwargs = ', '.join(kwargs.keys())
205 raise ValueError(
206 'Unexpected keyword arguments: ' + extra_kwargs
208 json_obj = json
209 if is_text:
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')
216 def __repr__(self):
217 L = []
218 padding = ' ' * 4
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__):
227 return False
229 return self.__dict__ == other.__dict__
231 def __ne__(self, other):
232 return not (self == other)
234 def __dir__(self):
235 return (
236 'success',
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__
264 class Client(Iface):
265 _fbthrift_force_cpp_transport = False
267 def __enter__(self):
268 if self._fbthrift_cpp_transport:
269 self._fbthrift_cpp_transport.__enter__()
270 return self
272 def __exit__(self, type, value, tb):
273 if self._fbthrift_cpp_transport:
274 self._fbthrift_cpp_transport.__exit__(type, value, tb)
275 if self._iprot:
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
282 if oprot != None:
283 self._oprot = oprot
284 self._seqid = 0
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)
290 else:
291 try:
292 self._oprot.trans.set_persistent_header(key, value)
293 except AttributeError:
294 pass
296 def get_persistent_headers(self):
297 if self._fbthrift_cpp_transport:
298 return self._fbthrift_cpp_transport.get_persistent_headers()
299 try:
300 return self._oprot.trans.get_write_persistent_headers()
301 except AttributeError:
302 return {}
304 def clear_persistent_headers(self):
305 if self._fbthrift_cpp_transport:
306 self._fbthrift_cpp_transport.clear_persistent_headers()
307 else:
308 try:
309 self._oprot.trans.clear_persistent_headers()
310 except AttributeError:
311 pass
313 def set_onetime_header(self, key, value):
314 if self._fbthrift_cpp_transport:
315 self._fbthrift_cpp_transport.set_onetime_header(key, value)
316 else:
317 try:
318 self._oprot.trans.set_header(key, value)
319 except AttributeError:
320 pass
322 def get_last_response_headers(self):
323 if self._fbthrift_cpp_transport:
324 return self._fbthrift_cpp_transport.get_last_response_headers()
325 try:
326 return self._iprot.trans.get_headers()
327 except AttributeError:
328 return {}
330 def set_max_frame_size(self, size):
331 if self._fbthrift_cpp_transport:
332 pass
333 else:
334 try:
335 self._oprot.trans.set_max_frame_size(size)
336 except AttributeError:
337 pass
339 def bar(self, ):
340 if (self._fbthrift_cpp_transport):
341 args = bar_args()
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)
346 self.send_bar()
347 return self.recv_bar()
349 def send_bar(self, ):
350 self._oprot.writeMessageBegin('bar', TMessageType.CALL, self._seqid)
351 args = bar_args()
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()
360 x.read(self._iprot)
361 self._iprot.readMessageEnd()
362 raise x
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):
372 _onewayMethods = ()
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):
383 l = []
384 l.extend(Processor._onewayMethods)
385 return tuple(l)
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()
393 try:
394 result.success = self._handler.bar()
395 except:
396 ex = sys.exc_info()[1]
397 self._event_handler.handlerError(handler_ctx, 'bar', ex)
398 result = Thrift.TApplicationException(message=repr(ex))
399 return result
401 Iface._processor_type = Processor
403 class ContextProcessor(ContextIface, TProcessor):
404 _onewayMethods = ()
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):
415 l = []
416 l.extend(ContextProcessor._onewayMethods)
417 return tuple(l)
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()
425 try:
426 result.success = self._handler.bar(handler_ctx)
427 except:
428 ex = sys.exc_info()[1]
429 self._event_handler.handlerError(handler_ctx, 'bar', ex)
430 result = Thrift.TApplicationException(message=repr(ex))
431 return result
433 ContextIface._processor_type = ContextProcessor
435 fix_spec(all_structs)
436 del all_structs