142
142
# instance to the method that does the real CallMethod work.
143
143
def _WrapCallMethod(srvc, method_descriptor,
144
144
rpc_controller, request, callback):
145
self._CallMethod(srvc, method_descriptor,
145
return self._CallMethod(srvc, method_descriptor,
146
146
rpc_controller, request, callback)
148
148
cls.CallMethod = _WrapCallMethod
149
cls.GetDescriptor = self._GetDescriptor
149
cls.GetDescriptor = staticmethod(lambda: self.descriptor)
150
cls.GetDescriptor.__doc__ = "Returns the service descriptor."
150
151
cls.GetRequestClass = self._GetRequestClass
151
152
cls.GetResponseClass = self._GetResponseClass
152
153
for method in self.descriptor.methods:
153
154
setattr(cls, method.name, self._GenerateNonImplementedMethod(method))
155
def _GetDescriptor(self):
156
"""Retrieves the service descriptor.
159
The descriptor of the service (of type ServiceDescriptor).
161
return self.descriptor
163
156
def _CallMethod(self, srvc, method_descriptor,
164
157
rpc_controller, request, callback):
165
158
"""Calls the method described by a given method descriptor.
175
168
raise RuntimeError(
176
169
'CallMethod() given method descriptor for wrong service type.')
177
170
method = getattr(srvc, method_descriptor.name)
178
method(rpc_controller, request, callback)
171
return method(rpc_controller, request, callback)
180
173
def _GetRequestClass(self, method_descriptor):
181
174
"""Returns the class of the request protocol message.
270
263
setattr(cls, method.name, self._GenerateStubMethod(method))
272
265
def _GenerateStubMethod(self, method):
273
return lambda inst, rpc_controller, request, callback: self._StubMethod(
274
inst, method, rpc_controller, request, callback)
266
return (lambda inst, rpc_controller, request, callback=None:
267
self._StubMethod(inst, method, rpc_controller, request, callback))
276
269
def _StubMethod(self, stub, method_descriptor,
277
270
rpc_controller, request, callback):
283
276
rpc_controller: Rpc controller to execute the method.
284
277
request: Request protocol message.
285
278
callback: A callback to execute when the method finishes.
280
Response message (in case of blocking call).
287
stub.rpc_channel.CallMethod(
282
return stub.rpc_channel.CallMethod(
288
283
method_descriptor, rpc_controller, request,
289
284
method_descriptor.output_type._concrete_class, callback)