1# 2# Autogenerated by Thrift 3# 4# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5# @generated 6# 7 8from __future__ import absolute_import 9import sys 10from thrift.util.Recursive import fix_spec 11from thrift.Thrift import TType, TMessageType, TPriority, TRequestContext, TProcessorEventHandler, TServerInterface, TProcessor, TException, TApplicationException, UnimplementedTypedef 12from thrift.protocol.TProtocol import TProtocolException 13 14from json import loads 15import sys 16if sys.version_info[0] >= 3: 17 long = int 18 19from .ttypes import UTF8STRINGS, Foo, Baz, Bar, StructWithFieldAdapter, SetWithAdapter, ListWithElemAdapter, StructWithAdapter, UnionWithAdapter 20import thrift.annotation.cpp.ttypes 21 22import my 23 24from thrift.Thrift import TProcessor 25import pprint 26import warnings 27from thrift import Thrift 28from thrift.transport import TTransport 29from thrift.protocol import TBinaryProtocol 30from thrift.protocol import TCompactProtocol 31from thrift.protocol import THeaderProtocol 32fastproto = None 33try: 34 from thrift.protocol import fastproto 35except ImportError: 36 pass 37 38all_structs = [] 39UTF8STRINGS = bool(0) or sys.version_info.major >= 3 40 41from thrift.util.Decorators import ( 42 future_process_main, 43 future_process_method, 44 process_main as thrift_process_main, 45 process_method as thrift_process_method, 46 should_run_on_thread, 47 write_results_after_future, 48) 49 50class Iface: 51 def func(self, arg1=None, arg2=None, arg3=None): 52 """ 53 Parameters: 54 - arg1 55 - arg2 56 - arg3 57 """ 58 pass 59 60 61class ContextIface: 62 def func(self, handler_ctx, arg1=None, arg2=None, arg3=None): 63 """ 64 Parameters: 65 - arg1 66 - arg2 67 - arg3 68 """ 69 pass 70 71 72# HELPER FUNCTIONS AND STRUCTURES 73 74class func_args: 75 """ 76 Attributes: 77 - arg1 78 - arg2 79 - arg3 80 """ 81 82 thrift_spec = None 83 thrift_field_annotations = None 84 thrift_struct_annotations = None 85 __init__ = None 86 @staticmethod 87 def isUnion(): 88 return False 89 90 def read(self, iprot): 91 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: 92 fastproto.decode(self, iprot.trans, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=0) 93 return 94 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: 95 fastproto.decode(self, iprot.trans, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=2) 96 return 97 iprot.readStructBegin() 98 while True: 99 (fname, ftype, fid) = iprot.readFieldBegin() 100 if ftype == TType.STOP: 101 break 102 if fid == 1: 103 if ftype == TType.STRING: 104 self.arg1 = iprot.readString().decode('utf-8') if UTF8STRINGS else iprot.readString() 105 else: 106 iprot.skip(ftype) 107 elif fid == 2: 108 if ftype == TType.STRING: 109 self.arg2 = iprot.readString().decode('utf-8') if UTF8STRINGS else iprot.readString() 110 else: 111 iprot.skip(ftype) 112 elif fid == 3: 113 if ftype == TType.STRUCT: 114 self.arg3 = Foo() 115 self.arg3.read(iprot) 116 else: 117 iprot.skip(ftype) 118 else: 119 iprot.skip(ftype) 120 iprot.readFieldEnd() 121 iprot.readStructEnd() 122 123 def write(self, oprot): 124 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: 125 oprot.trans.write(fastproto.encode(self, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=0)) 126 return 127 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: 128 oprot.trans.write(fastproto.encode(self, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=2)) 129 return 130 oprot.writeStructBegin('func_args') 131 if self.arg1 != None: 132 oprot.writeFieldBegin('arg1', TType.STRING, 1) 133 oprot.writeString(self.arg1.encode('utf-8')) if UTF8STRINGS and not isinstance(self.arg1, bytes) else oprot.writeString(self.arg1) 134 oprot.writeFieldEnd() 135 if self.arg2 != None: 136 oprot.writeFieldBegin('arg2', TType.STRING, 2) 137 oprot.writeString(self.arg2.encode('utf-8')) if UTF8STRINGS and not isinstance(self.arg2, bytes) else oprot.writeString(self.arg2) 138 oprot.writeFieldEnd() 139 if self.arg3 != None: 140 oprot.writeFieldBegin('arg3', TType.STRUCT, 3) 141 self.arg3.write(oprot) 142 oprot.writeFieldEnd() 143 oprot.writeFieldStop() 144 oprot.writeStructEnd() 145 146 def readFromJson(self, json, is_text=True, **kwargs): 147 relax_enum_validation = bool(kwargs.pop('relax_enum_validation', False)) 148 set_cls = kwargs.pop('custom_set_cls', set) 149 dict_cls = kwargs.pop('custom_dict_cls', dict) 150 if kwargs: 151 extra_kwargs = ', '.join(kwargs.keys()) 152 raise ValueError( 153 'Unexpected keyword arguments: ' + extra_kwargs 154 ) 155 json_obj = json 156 if is_text: 157 json_obj = loads(json) 158 if 'arg1' in json_obj and json_obj['arg1'] is not None: 159 self.arg1 = json_obj['arg1'] 160 if 'arg2' in json_obj and json_obj['arg2'] is not None: 161 self.arg2 = json_obj['arg2'] 162 if 'arg3' in json_obj and json_obj['arg3'] is not None: 163 self.arg3 = Foo() 164 self.arg3.readFromJson(json_obj['arg3'], is_text=False, relax_enum_validation=relax_enum_validation, custom_set_cls=set_cls, custom_dict_cls=dict_cls) 165 166 def __repr__(self): 167 L = [] 168 padding = ' ' * 4 169 if self.arg1 is not None: 170 value = pprint.pformat(self.arg1, indent=0) 171 value = padding.join(value.splitlines(True)) 172 L.append(' arg1=%s' % (value)) 173 if self.arg2 is not None: 174 value = pprint.pformat(self.arg2, indent=0) 175 value = padding.join(value.splitlines(True)) 176 L.append(' arg2=%s' % (value)) 177 if self.arg3 is not None: 178 value = pprint.pformat(self.arg3, indent=0) 179 value = padding.join(value.splitlines(True)) 180 L.append(' arg3=%s' % (value)) 181 return "%s(%s)" % (self.__class__.__name__, "\n" + ",\n".join(L) if L else '') 182 183 def __eq__(self, other): 184 if not isinstance(other, self.__class__): 185 return False 186 187 return self.__dict__ == other.__dict__ 188 189 def __ne__(self, other): 190 return not (self == other) 191 192 # Override the __hash__ function for Python3 - t10434117 193 __hash__ = object.__hash__ 194 195all_structs.append(func_args) 196func_args.thrift_spec = ( 197 None, # 0 198 (1, TType.STRING, 'arg1', True, None, 2, ), # 1 199 (2, TType.STRING, 'arg2', True, None, 2, ), # 2 200 (3, TType.STRUCT, 'arg3', [Foo, Foo.thrift_spec, False], None, 2, ), # 3 201) 202 203func_args.thrift_struct_annotations = { 204} 205func_args.thrift_field_annotations = { 206} 207 208def func_args__init__(self, arg1=None, arg2=None, arg3=None,): 209 self.arg1 = arg1 210 self.arg2 = arg2 211 self.arg3 = arg3 212 213func_args.__init__ = func_args__init__ 214 215def func_args__setstate__(self, state): 216 state.setdefault('arg1', None) 217 state.setdefault('arg2', None) 218 state.setdefault('arg3', None) 219 self.__dict__ = state 220 221func_args.__getstate__ = lambda self: self.__dict__.copy() 222func_args.__setstate__ = func_args__setstate__ 223 224class func_result: 225 """ 226 Attributes: 227 - success 228 """ 229 230 thrift_spec = None 231 thrift_field_annotations = None 232 thrift_struct_annotations = None 233 __init__ = None 234 @staticmethod 235 def isUnion(): 236 return False 237 238 def read(self, iprot): 239 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: 240 fastproto.decode(self, iprot.trans, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=0) 241 return 242 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: 243 fastproto.decode(self, iprot.trans, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=2) 244 return 245 iprot.readStructBegin() 246 while True: 247 (fname, ftype, fid) = iprot.readFieldBegin() 248 if ftype == TType.STOP: 249 break 250 if fid == 0: 251 if ftype == TType.I32: 252 self.success = iprot.readI32() 253 else: 254 iprot.skip(ftype) 255 else: 256 iprot.skip(ftype) 257 iprot.readFieldEnd() 258 iprot.readStructEnd() 259 260 def write(self, oprot): 261 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: 262 oprot.trans.write(fastproto.encode(self, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=0)) 263 return 264 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: 265 oprot.trans.write(fastproto.encode(self, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=2)) 266 return 267 oprot.writeStructBegin('func_result') 268 if self.success != None: 269 oprot.writeFieldBegin('success', TType.I32, 0) 270 oprot.writeI32(self.success) 271 oprot.writeFieldEnd() 272 oprot.writeFieldStop() 273 oprot.writeStructEnd() 274 275 def readFromJson(self, json, is_text=True, **kwargs): 276 relax_enum_validation = bool(kwargs.pop('relax_enum_validation', False)) 277 set_cls = kwargs.pop('custom_set_cls', set) 278 dict_cls = kwargs.pop('custom_dict_cls', dict) 279 if kwargs: 280 extra_kwargs = ', '.join(kwargs.keys()) 281 raise ValueError( 282 'Unexpected keyword arguments: ' + extra_kwargs 283 ) 284 json_obj = json 285 if is_text: 286 json_obj = loads(json) 287 if 'success' in json_obj and json_obj['success'] is not None: 288 self.success = json_obj['success'] 289 if self.success > 0x7fffffff or self.success < -0x80000000: 290 raise TProtocolException(TProtocolException.INVALID_DATA, 'number exceeds limit in field') 291 292 def __repr__(self): 293 L = [] 294 padding = ' ' * 4 295 if self.success is not None: 296 value = pprint.pformat(self.success, indent=0) 297 value = padding.join(value.splitlines(True)) 298 L.append(' success=%s' % (value)) 299 return "%s(%s)" % (self.__class__.__name__, "\n" + ",\n".join(L) if L else '') 300 301 def __eq__(self, other): 302 if not isinstance(other, self.__class__): 303 return False 304 305 return self.__dict__ == other.__dict__ 306 307 def __ne__(self, other): 308 return not (self == other) 309 310 # Override the __hash__ function for Python3 - t10434117 311 __hash__ = object.__hash__ 312 313all_structs.append(func_result) 314func_result.thrift_spec = ( 315 (0, TType.I32, 'success', None, None, 2, ), # 0 316) 317 318func_result.thrift_struct_annotations = { 319} 320func_result.thrift_field_annotations = { 321} 322 323def func_result__init__(self, success=None,): 324 self.success = success 325 326func_result.__init__ = func_result__init__ 327 328def func_result__setstate__(self, state): 329 state.setdefault('success', None) 330 self.__dict__ = state 331 332func_result.__getstate__ = lambda self: self.__dict__.copy() 333func_result.__setstate__ = func_result__setstate__ 334 335class Client(Iface): 336 def __enter__(self): 337 return self 338 339 def __exit__(self, type, value, tb): 340 self._iprot.trans.close() 341 if self._iprot is not self._oprot: 342 self._oprot.trans.close() 343 344 def __init__(self, iprot, oprot=None): 345 self._iprot = self._oprot = iprot 346 if oprot != None: 347 self._oprot = oprot 348 self._seqid = 0 349 350 def func(self, arg1=None, arg2=None, arg3=None): 351 """ 352 Parameters: 353 - arg1 354 - arg2 355 - arg3 356 """ 357 self.send_func(arg1, arg2, arg3) 358 return self.recv_func() 359 360 def send_func(self, arg1=None, arg2=None, arg3=None): 361 self._oprot.writeMessageBegin('func', TMessageType.CALL, self._seqid) 362 args = func_args() 363 args.arg1 = arg1 364 args.arg2 = arg2 365 args.arg3 = arg3 366 args.write(self._oprot) 367 self._oprot.writeMessageEnd() 368 self._oprot.trans.flush() 369 370 def recv_func(self, ): 371 (fname, mtype, rseqid) = self._iprot.readMessageBegin() 372 if mtype == TMessageType.EXCEPTION: 373 x = TApplicationException() 374 x.read(self._iprot) 375 self._iprot.readMessageEnd() 376 raise x 377 result = func_result() 378 result.read(self._iprot) 379 self._iprot.readMessageEnd() 380 if result.success != None: 381 return result.success 382 raise TApplicationException(TApplicationException.MISSING_RESULT, "func failed: unknown result"); 383 384 385class Processor(Iface, TProcessor): 386 _onewayMethods = () 387 388 def __init__(self, handler): 389 TProcessor.__init__(self) 390 self._handler = handler 391 self._processMap = {} 392 self._priorityMap = {} 393 self._processMap["func"] = Processor.process_func 394 self._priorityMap["func"] = TPriority.NORMAL 395 396 def onewayMethods(self): 397 l = [] 398 l.extend(Processor._onewayMethods) 399 return tuple(l) 400 401 @thrift_process_main() 402 def process(self,): pass 403 404 @thrift_process_method(func_args, oneway=False) 405 def process_func(self, args, handler_ctx): 406 result = func_result() 407 try: 408 result.success = self._handler.func(args.arg1, args.arg2, args.arg3) 409 except: 410 ex = sys.exc_info()[1] 411 self._event_handler.handlerError(handler_ctx, 'func', ex) 412 result = Thrift.TApplicationException(message=repr(ex)) 413 return result 414 415Iface._processor_type = Processor 416 417class ContextProcessor(ContextIface, TProcessor): 418 _onewayMethods = () 419 420 def __init__(self, handler): 421 TProcessor.__init__(self) 422 self._handler = handler 423 self._processMap = {} 424 self._priorityMap = {} 425 self._processMap["func"] = ContextProcessor.process_func 426 self._priorityMap["func"] = TPriority.NORMAL 427 428 def onewayMethods(self): 429 l = [] 430 l.extend(ContextProcessor._onewayMethods) 431 return tuple(l) 432 433 @thrift_process_main() 434 def process(self,): pass 435 436 @thrift_process_method(func_args, oneway=False) 437 def process_func(self, args, handler_ctx): 438 result = func_result() 439 try: 440 result.success = self._handler.func(handler_ctx, args.arg1, args.arg2, args.arg3) 441 except: 442 ex = sys.exc_info()[1] 443 self._event_handler.handlerError(handler_ctx, 'func', ex) 444 result = Thrift.TApplicationException(message=repr(ex)) 445 return result 446 447ContextIface._processor_type = ContextProcessor 448 449fix_spec(all_structs) 450del all_structs 451 452