def method_delegate(**methods):
    """
    Construct a renderer that delegates based on the request's HTTP method.

    """

    methods = {k.upper(): v for k, v in iteritems(methods)}

    if PY3:
        methods = {k.encode("utf-8"): v for k, v in iteritems(methods)}

    def render(request):
        renderer = methods.get(request.method)
        if renderer is None:
            return Response(code=405)
        return renderer(request)
    return render
Construct a renderer that delegates based on the request's HTTP method.