def testDefaultDecorationNoKwdsFails(self): def fn(a): return a with self.assertRaisesRegexp( ValueError, 'Functions with no keyword arguments must specify ' 'max_positional_args'): util.positional(fn)
def __new_async_method(cls, remote): """Create asynchronous method for Async handler. Args: remote: RemoteInfo to create method for. """ def async_method(self, *args, **kwargs): """Asynchronous remote method. Args: self: Instance of StubBase.Async subclass. Stub methods either take a single positional argument when a full request message is passed in, or keyword arguments, but not both. See docstring for StubBase for more information on how to use remote stub methods. Returns: Rpc instance used to represent asynchronous RPC. """ if args and kwargs: raise TypeError('May not provide both args and kwargs') if not args: # Construct request object from arguments. request = remote.request_type() for name, value in kwargs.iteritems(): setattr(request, name, value) else: # First argument is request object. request = args[0] return self.transport.send_rpc(remote, request) async_method.__name__ = remote.method.__name__ async_method = util.positional(2)(async_method) async_method.remote = remote return async_method