code: def register(dispatcher, service, handler=None, method=None):
      
  
      def decorator(method, handler):
          if not method:
              method = handler.__name__
  
          function = getattr(service, method, None)
          assert function, (
              'Service "%s" does not define method "%s"' % (service.name, method)
          )
          assert not function.oneway
  
          dispatcher.register(
              function.endpoint,
              build_handler(function, handler),
              ThriftRWSerializer(service._module, function._request_cls),
              ThriftRWSerializer(service._module, function._response_cls),
          )
          return handler
  
      if handler is None:
          return partial(decorator, method)
      else:
          return decorator(method, handler)
docs: :param dispatcher:
          RequestDispatcher against which the new endpoint will be registered.
      :param Service service:
          Service object representing the service whose endpoint is being
          registered.
      :param handler:
          A function implementing the given Thrift function.
      :param method:
          If specified, name of the method being registered. Defaults to the
          name of the ``handler`` function.