@ -133,7 +133,7 @@ class _ServiceBuilder(object):
"""
"""
self . descriptor = service_descriptor
self . descriptor = service_descriptor
def BuildService ( self , cls ) :
def BuildService ( builder , cls ) :
""" Constructs the service class.
""" Constructs the service class.
Args :
Args :
@ -143,18 +143,25 @@ class _ServiceBuilder(object):
# CallMethod needs to operate with an instance of the Service class. This
# CallMethod needs to operate with an instance of the Service class. This
# internal wrapper function exists only to be able to pass the service
# internal wrapper function exists only to be able to pass the service
# instance to the method that does the real CallMethod work.
# instance to the method that does the real CallMethod work.
def _WrapCallMethod ( srvc , method_descriptor ,
# Making sure to use exact argument names from the abstract interface in
rpc_controller , request , callback ) :
# service.py to match the type signature
return self . _CallMethod ( srvc , method_descriptor ,
def _WrapCallMethod ( self , method_descriptor ,
rpc_controller , request , callback )
rpc_controller , request , done ) :
self . cls = cls
return builder . _CallMethod ( self , method_descriptor ,
rpc_controller , request , done )
def _WrapGetRequestClass ( self , method_descriptor ) :
return builder . _GetRequestClass ( method_descriptor )
def _WrapGetResponseClass ( self , method_descriptor ) :
return builder . _GetResponseClass ( method_descriptor )
builder . cls = cls
cls . CallMethod = _WrapCallMethod
cls . CallMethod = _WrapCallMethod
cls . GetDescriptor = staticmethod ( lambda : self . descriptor )
cls . GetDescriptor = staticmethod ( lambda : builder . descriptor )
cls . GetDescriptor . __doc__ = " Returns the service descriptor. "
cls . GetDescriptor . __doc__ = " Returns the service descriptor. "
cls . GetRequestClass = self . _GetRequestClass
cls . GetRequestClass = _Wrap GetRequestClass
cls . GetResponseClass = self . _GetResponseClass
cls . GetResponseClass = _Wrap GetResponseClass
for method in self . descriptor . methods :
for method in builder . descriptor . methods :
setattr ( cls , method . name , self . _GenerateNonImplementedMethod ( method ) )
setattr ( cls , method . name , builder . _GenerateNonImplementedMethod ( method ) )
def _CallMethod ( self , srvc , method_descriptor ,
def _CallMethod ( self , srvc , method_descriptor ,
rpc_controller , request , callback ) :
rpc_controller , request , callback ) :