<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def register(dispatcher, service_module, handler, method=None, service=None):
 """Registers a Thrift service method with the given RequestDispatcher. .. code-block:: python # For, # # service HelloWorld { string hello(1: string name); } import tchannel.thrift import HelloWorld def hello(request, response):
 name = request.args.name response.write_result("Hello, %s" % name) dispatcher = RequestDispatcher() tchannel.thrift.register(dispatcher, HelloWorld, hello) :param dispatcher: TChannel dispatcher with which the Thrift service will be registered. :param service_module: The service module generated by Thrift. This module contains the service ``Iface``, ``Client``, ``Processor``, etc. classes. :param handler: A function implementing the request handler. The function must accept a ``request``, a ``response``, and a ``tchannel``. :param service: Thrift service name. This is the `service` name specified in the Thrift IDL. If omitted, it is automatically determined based on the name of ``service_module``. :param method: Name of the method. Defaults to the name of the ``handler`` function. """

    if not service:
        service = service_module.__name__.rsplit('.', 1)[-1]
    if not method:
        method = handler.__name__
    assert service, 'A service name could not be determined'
    assert method, 'A method name could not be determined'

    assert hasattr(service_module.Iface, method), (
        "Service %s doesn't define method %s" % (service, method)
    )
    assert hasattr(service_module, method + '_result'), (
        "oneway methods are not yet supported"
    )

    endpoint = '%s::%s' % (service, method)
    args_type = getattr(service_module, method + '_args')
    result_type = getattr(service_module, method + '_result')

    # if the dispatcher is set to deal with handlers that
    # return responses, then use new api, else use deprecated
    if dispatcher._handler_returns_response:
        new_handler = build_handler(result_type, handler)
    else:
        new_handler = deprecated_build_handler(result_type, handler)

    dispatcher.register(
        endpoint,
        new_handler,
        ThriftSerializer(args_type),
        ThriftSerializer(result_type)
    )
    return handler