A decorator to mark HTTP methods a resource can handle.

    For example::

        class SomeRes(UrlResource):
            ...
            @methods(['GET', 'HEAD'])
            def handle_request(self, req):
                ...
            @handle_request.methods(['POST'])
            def handle_post(self, req):
                ...

    In this case, GET and HEAD requests will be dispatched to
    ``handle_request``, and POST requests will be dispatched to
    ``handle_post``. All other request methods will cause a
    *501 Not Implemented* error.

def methods(method_list):
    """A decorator to mark HTTP methods a resource can handle.

    For example::

        class SomeRes(UrlResource):
            ...
            @methods(['GET', 'HEAD'])
            def handle_request(self, req):
                ...
            @handle_request.methods(['POST'])
            def handle_post(self, req):
                ...

    In this case, GET and HEAD requests will be dispatched to
    ``handle_request``, and POST requests will be dispatched to
    ``handle_post``. All other request methods will cause a
    *501 Not Implemented* error.
    """

    assert isinstance(method_list, list) and len(method_list) > 0

    def deco(handler):
        d = _HandleRequestDict()
        for m in method_list:
            d[m.upper()] = handler
        return d

    return deco