<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def rpc_method(func, doc=None, format='json', request_handler=None):
    '''A decorator which exposes a function ``func`` as an rpc function.

    :param func: The function to expose.
    :param doc: Optional doc string. If not provided the doc string of
        ``func`` will be used.
    :param format: Optional output format.
    :param request_handler: function which takes ``request``, ``format``
        and ``kwargs`` and return a new ``kwargs`` to be passed to ``func``.
        It can be used to add additional parameters based on request and
        format.
    '''
    def _(self, *args, **kwargs):
        request = args[0]
        if request_handler:
            kwargs = request_handler(request, format, kwargs)
        try:
            return func(*args, **kwargs)
        except TypeError:
            msg = checkarity(func, args, kwargs)
            if msg:
                raise InvalidParams('Invalid Parameters. %s' % msg)
            else:
                raise

    _.__doc__ = doc or func.__doc__
    _.__name__ = func.__name__
    _.FromApi = True
    return _