<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_method(service_module, service_name, method_name):
 """Generate a method for the given Thrift service. :param service_module: Thrift-generated service module :param service_name: Name of the Thrift service :param method_name: Method being called """

    assert service_module
    assert service_name
    assert method_name

    args_type = getattr(service_module, method_name + '_args')
    result_type = getattr(service_module, method_name + '_result', None)
    serializer = ThriftSerializer(result_type)
    # oneway not currently supported
    # TODO - write test for this
    if result_type is None:
        def not_supported(self, *args, **kwags):
            raise OneWayNotSupportedError(
                'TChannel+Thrift does not currently support oneway procedues'
            )
        return not_supported

    result_spec = result_type.thrift_spec
    # result_spec is a tuple of tuples in the form:
    #
    #   (fieldId, fieldType, fieldName, ...)
    #
    # Where "..." is other information we don't care about right now.
    #
    # result_spec will be empty if there is no return value or exception for
    # the method.
    #
    # Its first element, with field ID 0, contains the spec for the return
    # value. It is None if the result type is void but the method may still
    # throw exceptions.
    #
    # Elements after the first one are specs for the exceptions.

    endpoint = '%s::%s' % (service_name, method_name)

    @gen.coroutine
    def send(self, *args, **kwargs):
        params = inspect.getcallargs(
            getattr(service_module.Iface, method_name), self, *args, **kwargs
        )
        params.pop('self')  # self is already known

        # $methodName_args is the implicit struct containing the various
        # method parameters.
        call_args = args_type()
        for name, value in params.items():
            setattr(call_args, name, value)

        tracer = tracing.ClientTracer(channel=self.tchannel)
        span, headers = tracer.start_span(
            service=service_name, endpoint=method_name, headers={}
        )

        body = serializer.serialize_body(call_args)
        header = serializer.serialize_header(headers)

        # Glue for old API.
        if hasattr(self.tchannel, 'request'):
            tracing.apply_trace_flag(span, self.trace, True)
            with span:
                response = yield self.tchannel.request(
                    hostport=self.hostport, service=self.service
                ).send(
                    arg1=endpoint,
                    arg2=header,
                    arg3=body,  # body
                    headers=self.protocol_headers,
                )
                body = yield response.get_body()
        else:
            with span:
                response = yield self.tchannel.call(
                    scheme=schemes.THRIFT,
                    service=self.service,
                    arg1=endpoint,
                    arg2=header,
                    arg3=body,
                    hostport=self.hostport,
                    trace=self.trace,
                    tracing_span=span
                    # TODO: Need to handle these!
                    # headers=self.protocol_headers,
                )
                body = response.body

        call_result = serializer.deserialize_body(body)

        if not result_spec:
            # void return type and no exceptions allowed
            raise gen.Return(None)

        for exc_spec in result_spec[1:]:
            # May have failed with an exception
            exc = getattr(call_result, exc_spec[2])
            if exc is not None:
                raise exc

        if result_spec[0]:
            # Non-void return type. Return the result.
            success = getattr(call_result, result_spec[0][2])
            if success is not None:
                raise gen.Return(success)
        else:
            # No return type specified and no exceptions raised.
            raise gen.Return(None)

        # Expected a result but nothing was present in the object. Something
        # went wrong.
        from thrift import Thrift
        raise Thrift.TApplicationException(
            Thrift.TApplicationException.MISSING_RESULT,
            '%s failed: did not receive a result as expected' % method_name
        )
        # TODO: We should probably throw a custom exception instead.

    send.__name__ = method_name
    return send