<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> class GeneratedServiceType ( type ) : <EOL> """<STR_LIT>""" <EOL> _DESCRIPTOR_KEY = '<STR_LIT>' <EOL> def __init__ ( cls , name , bases , dictionary ) : <EOL> """<STR_LIT>""" <EOL> if GeneratedServiceType . _DESCRIPTOR_KEY not in dictionary : <EOL> return <EOL> descriptor = dictionary [ GeneratedServiceType . _DESCRIPTOR_KEY ] <EOL> service_builder = _ServiceBuilder ( descriptor ) <EOL> service_builder . BuildService ( cls ) <EOL> class GeneratedServiceStubType ( GeneratedServiceType ) : <EOL> """<STR_LIT>""" <EOL> _DESCRIPTOR_KEY = '<STR_LIT>' <EOL> def __init__ ( cls , name , bases , dictionary ) : <EOL> """<STR_LIT>""" <EOL> super ( GeneratedServiceStubType , cls ) . __init__ ( name , bases , dictionary ) <EOL> if GeneratedServiceStubType . _DESCRIPTOR_KEY not in dictionary : <EOL> return <EOL> descriptor = dictionary [ GeneratedServiceStubType . _DESCRIPTOR_KEY ] <EOL> service_stub_builder = _ServiceStubBuilder ( descriptor ) <EOL> service_stub_builder . BuildServiceStub ( cls ) <EOL> class _ServiceBuilder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , service_descriptor ) : <EOL> """<STR_LIT>""" <EOL> self . descriptor = service_descriptor <EOL> def BuildService ( self , cls ) : <EOL> """<STR_LIT>""" <EOL> def _WrapCallMethod ( srvc , method_descriptor , <EOL> rpc_controller , request , callback ) : <EOL> return self . _CallMethod ( srvc , method_descriptor , <EOL> rpc_controller , request , callback ) <EOL> self . cls = cls <EOL> cls . CallMethod = _WrapCallMethod <EOL> cls . GetDescriptor = staticmethod ( lambda : self . descriptor ) <EOL> cls . GetDescriptor . __doc__ = "<STR_LIT>" <EOL> cls . GetRequestClass = self . _GetRequestClass <EOL> cls . GetResponseClass = self . _GetResponseClass <EOL> for method in self . descriptor . methods : <EOL> setattr ( cls , method . name , self . _GenerateNonImplementedMethod ( method ) ) <EOL> def _CallMethod ( self , srvc , method_descriptor , <EOL> rpc_controller , request , callback ) : <EOL> """<STR_LIT>""" <EOL> if method_descriptor . containing_service != self . descriptor : <EOL> raise RuntimeError ( <EOL> '<STR_LIT>' ) <EOL> method = getattr ( srvc , method_descriptor . name ) <EOL> return method ( rpc_controller , request , callback ) <EOL> def _GetRequestClass ( self , method_descriptor ) : <EOL> """<STR_LIT>""" <EOL> if method_descriptor . containing_service != self . descriptor : <EOL> raise RuntimeError ( <EOL> '<STR_LIT>' ) <EOL> return method_descriptor . input_type . _concrete_class <EOL> def _GetResponseClass ( self , method_descriptor ) : <EOL> """<STR_LIT>""" <EOL> if method_descriptor . containing_service != self . descriptor : <EOL> raise RuntimeError ( <EOL> '<STR_LIT>' ) <EOL> return method_descriptor . output_type . _concrete_class <EOL> def _GenerateNonImplementedMethod ( self , method ) : <EOL> """<STR_LIT>""" <EOL> return lambda inst , rpc_controller , request , callback : ( <EOL> self . _NonImplementedMethod ( method . name , rpc_controller , callback ) ) <EOL> def _NonImplementedMethod ( self , method_name , rpc_controller , callback ) : <EOL> """<STR_LIT>""" <EOL> rpc_controller . SetFailed ( '<STR_LIT>' % method_name ) <EOL> callback ( None ) <EOL> class _ServiceStubBuilder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , service_descriptor ) : <EOL> """<STR_LIT>""" <EOL> self . descriptor = service_descriptor <EOL> def BuildServiceStub ( self , cls ) : <EOL> """<STR_LIT>""" <EOL> def _ServiceStubInit ( stub , rpc_channel ) : <EOL> stub . rpc_channel = rpc_channel <EOL> self . cls = cls <EOL> cls . __init__ = _ServiceStubInit <EOL> for method in self . descriptor . methods : <EOL> setattr ( cls , method . name , self . _GenerateStubMethod ( method ) ) <EOL> def _GenerateStubMethod ( self , method ) : <EOL> return ( lambda inst , rpc_controller , request , callback = None : <EOL> self . _StubMethod ( inst , method , rpc_controller , request , callback ) ) <EOL> def _StubMethod ( self , stub , method_descriptor , <EOL> rpc_controller , request , callback ) : <EOL> """<STR_LIT>""" <EOL> return stub . rpc_channel . CallMethod ( <EOL> method_descriptor , rpc_controller , request , <EOL> method_descriptor . output_type . _concrete_class , callback ) </s>
