Binds a Pale API implementation to a webapp2 WSGIApplication

def bind_pale_to_webapp2(pale_app_module,
        webapp_wsgiapplication,
        route_prefix=None):
    """Binds a Pale API implementation to a webapp2 WSGIApplication"""

    if not isinstance(webapp_wsgiapplication, webapp2.WSGIApplication):
        raise TypeError("pale.adapters.webapp2.bind_pale_to_webapp2 expected "
                "the passed in webapp_wsgiapplication to be an instance of "
                "WSGIApplication, but it was an instance of %s instead."
                % (type(webapp_wsgiapplication), ))

    if not pale.is_pale_module(pale_app_module):
        raise TypeError("pale.adapters.webapp2.bind_pale_to_webapp2 expected "
                "the passed in pale_app_module to be a Python module with a "
                "`_module_type` value equal to `pale.ImplementationModule`, "
                "but it found an instance of %s instead."
                % (type(pale_app_module), ))

    endpoints = pale.extract_endpoints(pale_app_module)

    for endpoint in endpoints:
        endpoint._set_response_class(RESPONSE_CLASS)
        method = endpoint._http_method
        name = endpoint._route_name

        req_handler = pale_webapp2_request_handler_generator(endpoint)

        route_uri = endpoint._uri
        if route_prefix is not None:
            route_uri = "%s%s" % (route_prefix, route_uri)

        route = webapp2.Route(
                route_uri,
                handler=req_handler,
                name=name,
                handler_method='pale_handler',
                methods=[method, "OPTIONS"])
        webapp_wsgiapplication.router.add(route)