~ubuntu-branches/ubuntu/oneiric/protobuf/oneiric

« back to all changes in this revision

Viewing changes to python/google/protobuf/service_reflection.py

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2009-11-16 10:41:33 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091116104133-ykhy3deg5l4975tw
Tags: 2.1.0-1ubuntu1
* Merge from Debian testing.
* Remaining Ubuntu changes:
  - Disable the death tests on IA64, now as a quilt patch.
  - Don't use python2.4, also as a quilt patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
147
147
    self.cls = cls
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))
154
155
 
155
 
  def _GetDescriptor(self):
156
 
    """Retrieves the service descriptor.
157
 
 
158
 
    Returns:
159
 
      The descriptor of the service (of type ServiceDescriptor).
160
 
    """
161
 
    return self.descriptor
162
 
 
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)
179
172
 
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))
271
264
 
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))
275
268
 
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.
 
279
    Returns:
 
280
      Response message (in case of blocking call).
286
281
    """
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)